Skip to main content
HTTP actions allow you to build HTTP endpoints that execute Convex functions. They are registered using the httpRouter() and routed to specific paths and HTTP methods.

httpRouter

Create a new HTTP router instance for defining HTTP routes.
Returns: A new 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).
Requirements:
  • Paths must begin with /
  • Cannot use both path and pathPrefix in the same route
  • Paths starting with /.files/ or exactly /.files are reserved

Path prefix routing

Path prefix matching routes all requests with URLs starting with the specified prefix.
Requirements:
  • Path prefixes must begin with /
  • Path prefixes must end with /
  • Cannot use both path and pathPrefix in the same route
  • Path prefixes starting with /.files/ are reserved

getRoutes

Returns a list of all registered HTTP action routes.
Returns: An array of tuples containing [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.
Returns: A tuple [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:
  • GET
  • POST
  • PUT
  • DELETE
  • PATCH
  • OPTIONS
Note: 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 either RouteSpecWithPath 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 with httpAction() from _generated/server.

Complete examples

Basic HTTP router

Path prefix routing

Handling file uploads with storage

CORS handling

Importing handlers from separate files

See also