ArctonArcton
Fundamentals

Application

Create an Arcton app with `Arcton()` and see the full surface of an app instance.

Every Arcton app starts the same way — call Arcton() and you get an object you register routes and behavior on:

import { Arcton } from '@arcton/core'

const app = Arcton()

app.get('/', () => ({ ok: true }))

app.listen()

Every registration method — get, post, use, provide, parser — returns the same app, so calls chain:

import { Arcton } from '@arcton/core'

const app = Arcton()

app
  .use(async (ctx, next) => {
    console.log(ctx.request.method, new URL(ctx.request.url).pathname)
    await next()
  })
  .get('/health', () => ({ status: 'ok' }))

app.listen()

Prefixing an instance

Arcton() takes an optional config with one field, prefix:

import { Arcton } from '@arcton/core'

const api = Arcton({ prefix: '/api' })

api.get('/status', () => ({ ok: true }))

api.listen()

prefix is applied to every route and ws route registered directly on that instance — here, GET /api/status. It must be a static path (no :param or *wildcard segment), and '/' behaves the same as leaving it out. The same instance you configure a prefix on is also what you mount as a module inside another app — see Modules.

The app surface

MemberWhat it does
configthe ArctonConfig object you passed to Arcton()
get / post / put / delete / patch / head / optionsregister a route for that HTTP method — see HTTP Methods
wsregister a WebSocket route — see WebSockets
useadd global or path-scoped middleware, or mount a module — see Middleware and Modules
providecompose typed values onto ctx — see Providers
parserregister a body parser for a Content-Type — see Body Parsers
listenstart the server — see Listen Options

Each route method accepts either a handler (with optional middleware before it) or an options object with params / query / body schemas — see Validation Overview. What happens between a request arriving and a handler running is the subject of Request Lifecycle.

On this page