Junction guide / Introduction
Overview
Junction is the API realm of a FrontierJS app: services that answer over HTTP and WebSockets, a hook pipeline around every call, and the batteries an API needs. It runs on Bun and takes its model from a Litestone schema when one is installed.
const app = await createTestApp()
app.services.register(createService({
name: 'notes',
async create(ctx) { return { id: 1, ...ctx.data } },
}))
const res = await request(app).post('/notes').send({ title: 'Hello' })
if (res.status !== 201 || (res.body as { title: string }).title !== 'Hello') throw new Error('unexpected answer')
What else it can do
- A service named
notesis mounted at/noteswith no route written, andapp.service('notes')calls it in process before,afteranderrorhooks run around every method, whichever transport carried the call- One service answers HTTP, a WebSocket frame and an in-process call the same way
app.getandapp.posttake a raw route for what is not a servicechannels()pushes a write to the clients watching itcreateJunctionClientis the browser's typed side of the same services- The batteries, each behind a subpath:
/mail,/cache,/scheduler,/webhooks,/openapi,/outboxand more manifest()servesGET /manifest, listing the services, hooks, channels and every route a plugin added- Auth, jobs, integrations, notifications and agents are their own packages
In depth: README § Where Junction lives in an app, § What is actually mounted