httpRouter() and routed to specific paths and HTTP methods.
httpRouter
Create a new HTTP router instance for defining HTTP routes.HttpRouter instance.
HttpRouter
The HTTP router class for specifying paths and methods for HTTP actions.route
Register an HTTP action to respond to requests for a specific HTTP method and path or path prefix.RouteSpec
required
A route specification object containing the method, handler, and either
path or pathPrefix.Path routing
Exact path matching requires the request URL to match exactly (excluding trailing slash).- Paths must begin with
/ - Cannot use both
pathandpathPrefixin the same route - Paths starting with
/.files/or exactly/.filesare reserved
Path prefix routing
Path prefix matching routes all requests with URLs starting with the specified prefix.- Path prefixes must begin with
/ - Path prefixes must end with
/ - Cannot use both
pathandpathPrefixin the same route - Path prefixes starting with
/.files/are reserved
getRoutes
Returns a list of all registered HTTP action routes.[path, method, handler]. Path prefixes are returned with a * suffix (e.g., /api/*).
This method is used internally to populate the routes shown in the Convex dashboard Functions page.
lookup
Find the appropriate HTTP action for a given path and method.string
required
The request URL pathname to look up.
RoutableMethod | 'HEAD'
required
The HTTP method to look up.
[handler, method, routedPath] if a match is found, or null if no route matches.
For prefix routes, the returned path includes a * suffix.
HTTP methods
Supported methods
The following HTTP methods are supported by Convex HTTP actions:GETPOSTPUTDELETEPATCHOPTIONS
HEAD requests are automatically handled by running the GET handler and stripping the response body.
Method routing example
Types
RouteSpec
A union type representing a route specification. Can be eitherRouteSpecWithPath or RouteSpecWithPathPrefix.
RouteSpecWithPath
A route specification using exact path matching.string
required
Exact HTTP request path to route. Must start with
/.RoutableMethod
required
HTTP method to route (
"GET", "POST", "PUT", "DELETE", "PATCH", or "OPTIONS").PublicHttpAction
required
The HTTP action to execute when this route matches.
RouteSpecWithPathPrefix
A route specification using path prefix matching.string
required
HTTP request path prefix to route. Requests with paths starting with this value will be routed to the handler. Must start and end with
/.RoutableMethod
required
HTTP method to route (
"GET", "POST", "PUT", "DELETE", "PATCH", or "OPTIONS").PublicHttpAction
required
The HTTP action to execute when this route matches.
RoutableMethod
Type representing the HTTP methods supported by Convex HTTP actions.PublicHttpAction
An HTTP action that is part of your app’s public API. Created by wrapping a function withhttpAction() from _generated/server.