HTTP actions let you define custom HTTP endpoints that live outside Baseflare’s RPC system. While queries and mutations are invoked viaDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/nickruigrok/baseflare/llms.txt
Use this file to discover all available pages before exploring further.
POST /api/query/:name and POST /api/mutation/:name, HTTP actions handle arbitrary HTTP requests — webhooks from Stripe or GitHub, custom REST endpoints, file upload handlers, or any other use case where you need full control over the request and response lifecycle.
Defining an HTTP Action
UsehttpAction from baseflare/server to define a handler. The handler receives two arguments: ctx, an ActionCtx identical to the one available in regular actions, and request, the raw Web API Request object. It must return a Response or a Promise<Response>.
httpAction call wraps the handler in a typed HttpAction object. This object is what you pass to router.route() when registering the endpoint — the raw handler function is not passed directly.
ActionCtx in HTTP Actions
HTTP actions share exactly the sameActionCtx as regular actions. That means inside your handler you have access to:
ctx.runQuery(ref, args)— execute a query and read data from the database.ctx.runMutation(ref, args)— execute a mutation and write to the database.ctx.runAction(ref, args)— invoke another action, useful for chaining side effects.ctx.auth— theAuthobject, wherectx.auth.getUserIdentity()returns the authenticated user’s identity (ornullif unauthenticated).ctx.scheduler(planned — Phase 7b) — schedule deferred work viactx.scheduler.runAfter()andctx.scheduler.runAt().ctx.storage(planned — Phase 7a) — access file storage viactx.storage.store(),ctx.storage.getUrl(), and related methods.
HTTP actions run in the action context — they do not have direct
ctx.db
access. All database reads and writes must go through ctx.runQuery() and
ctx.runMutation(). This keeps the transaction boundary clear and prevents
long-running HTTP handlers from holding open database locks.Returning Responses
Because HTTP actions return a standard Web APIResponse, you have full control over the status code, headers, and body format.
Response constructor — JSON, plain text, binary data, or a ReadableStream for streaming responses.
Registering HTTP Actions
AnhttpAction handler by itself is not accessible over HTTP. You must register it on an HttpRouter by calling router.route() or router.routeWithPrefix(). The router maps HTTP method and path combinations to your handlers and is passed to createWorker as part of your Worker manifest.