HTTP routes

Plain HTTP for webhooks and other services.

1 MIN READView Markdown ↗

Some callers are not your app: a payment provider, a form, a script. Export routes from any api file to accept plain HTTP requests.

TypeScript
import { ApiError, type Routes } from 'arkapi/server'

export const routes: Routes = {
  'POST /announce': async (req) => {
    const token = process.env.ANNOUNCE_TOKEN
    if (!token || req.headers.get('Authorization') !== `Bearer ${token}`) {
      throw new ApiError('UNAUTHORIZED', 'Invalid token')
    }
    const text = await req.text()
    return Response.json({ accepted: text })
  },
  'PUT /items/:id': async (req, params) => Response.json({ id: params.id }),
}

Keys are METHOD /path; :name segments arrive in params. Handlers get the standard Request and return a Response.

The URLs are <base>/http/announce and <base>/http/items/123, where <base> is your app's URL (BASE in the generated client). A route refreshes live data like a mutation.

Terminal
curl -X POST https://arkapi.emincanozcan.com/apps/<app>/http/announce \
  -H 'Authorization: Bearer your-token' -d 'Hello from outside'

Set secrets with bunx arkapi env set ANNOUNCE_TOKEN=.... Browser cookies are not forwarded; use the Authorization header.

Tab to navigate results · Enter to open · Esc to close