Documentation 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.
HttpRouter manages the routing of custom HTTP requests to httpAction handlers. When a request arrives at your Worker, the router matches it by HTTP method and path — first trying exact matches, then falling back to prefix matches ordered by specificity. When multiple prefix routes match, the longest prefix wins. This gives you a predictable, conflict-free routing model without any ambiguity about which handler runs.
Creating a Router
Use thehttpRouter() factory function exported from baseflare/server to create a new HttpRouter instance. Register routes with router.route() or router.routeWithPrefix(), then export the router as the default export of your HTTP module.
createWorker via the http key in your Worker manifest, which wires it into the Worker’s request dispatch loop.
router.route(config)
router.route() registers an exact path match. The request must match both the HTTP method and the full path for the handler to fire.
The HttpRouteConfig object accepts the following properties:
| Property | Type | Description |
|---|---|---|
path | string | The exact path to match. Must start with /. |
method | string | The HTTP method to match (e.g. 'POST', 'GET'). Case-insensitive — normalized to uppercase internally. |
handler | HttpAction | An HttpAction created with httpAction(). |
router.routeWithPrefix(config)
router.routeWithPrefix() registers a prefix match. Any request whose path starts with pathPrefix and matches the given method will be routed to the handler. This is useful for routing whole subtrees — for example, mounting a versioned API namespace or delegating a range of paths to a single handler.
HttpPrefixRouteConfig object accepts the following properties:
| Property | Type | Description |
|---|---|---|
pathPrefix | string | The path prefix to match. Must start with /. |
method | string | The HTTP method to match. Case-insensitive. |
handler | HttpAction | An HttpAction created with httpAction(). |
pathPrefix. This means more-specific prefixes always win over broader ones, giving you predictable layering without conflicts.
Registering the same method and prefix combination twice throws an error.
router.lookup(method, path)
router.lookup() is an internal method used by createWorker to resolve a handler for each incoming request. It normalizes the method to uppercase, checks exact routes first, then scans prefix routes sorted by descending prefix length.
It returns the raw HttpActionHandler function if a match is found, or null if no registered route matches the request. You do not call this method in application code — it is part of the Worker dispatch plumbing.
Full Example
Here is a complete router setup with multiple routes — two exact-match webhook handlers and a prefix-match handler for an API namespace:Integrating with createWorker
Pass the router to createWorker via the http key in your Worker manifest. The schema, rules, and functions are also part of this manifest. createWorker wires everything together into a single Cloudflare Worker export.
http key is optional. If omitted, all custom HTTP paths return a 404. RPC routes (/api/query/*, /api/mutation/*, /api/action/*) are always handled regardless of whether an HttpRouter is provided.
RPC Routes vs HTTP Routes
Baseflare automatically generates RPC routes for every query, mutation, and
action you define. These live under
/api/query/*, /api/mutation/*, and
/api/action/* and are handled before custom HTTP routes are consulted.Custom HttpRouter routes are checked after RPC dispatch. Because the two
systems operate on different path prefixes, they never conflict — you can
safely register routes at any path that doesn’t start with /api/query/,
/api/mutation/, or /api/action/.Method Case
Method names passed to
router.route() and router.routeWithPrefix() are
case-insensitive. The strings 'post', 'POST', and 'Post' are all
normalized to 'POST' internally before registration and lookup. You can use
whichever casing you prefer — the router will match correctly regardless.