Class: HttpRouter
server.HttpRouter
HTTP router for specifying the paths and methods of httpActionGenerics
An example convex/http.js
file might look like this.
import { httpRouter } from "convex/server";
import { getMessagesByAuthor } from "./getMessagesByAuthor";
import { httpAction } from "./_generated/server";
const http = httpRouter();
// HTTP actions can be defined inline...
http.route({
path: "/message",
method: "POST",
handler: httpAction(async ({ runMutation }, request) => {
const { author, body } = await request.json();
await runMutation(api.sendMessage.default, { body, author });
return new Response(null, {
status: 200,
});
})
});
// ...or they can be imported from other files.
http.route({
path: "/getMessagesByAuthor",
method: "GET",
handler: getMessagesByAuthor,
});
// Convex expects the router to be the default export of `convex/http.js`.
export default http;
Constructors
constructor
• new HttpRouter()
Properties
exactRoutes
• exactRoutes: Map
<string
, Map
<"GET"
| "POST"
| "PUT"
| "DELETE"
| "OPTIONS"
| "PATCH"
, PublicHttpAction
>>
Defined in
prefixRoutes
• prefixRoutes: Map
<"GET"
| "POST"
| "PUT"
| "DELETE"
| "OPTIONS"
| "PATCH"
, Map
<string
, PublicHttpAction
>>
Defined in
isRouter
• isRouter: true