Skip to content

Commit cb91a77

Browse files
thomasballingerConvex, Inc.
authored andcommitted
HTTP code sample (#40895)
GitOrigin-RevId: 3474c2ec0ed1cd1fc1c7d2870ebd9a96ef339c8e
1 parent 8487cd2 commit cb91a77

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

npm-packages/docs/docs/functions/http-actions.mdx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ import Fetch from "!!raw-loader!@site/../private-demos/snippets/src/httpAuthCall
1212

1313
HTTP actions allow you to build an HTTP API right in Convex!
1414

15+
```ts title="convex/http.ts"
16+
import { httpRouter } from "convex/server";
17+
import { httpAction } from "./_generated/server";
18+
19+
const http = httpRouter();
20+
21+
http.route({
22+
path: "/",
23+
method: "GET",
24+
handler: httpAction(async (ctx, request) => {
25+
return new Response(`Hello from ${request.url}`);
26+
}),
27+
});
28+
export default http;
29+
```
30+
1531
HTTP actions take in a
1632
[Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) and return a
1733
[Response](https://developer.mozilla.org/en-US/docs/Web/API/Response) following
@@ -70,7 +86,7 @@ Here's an example:
7086
</>
7187

7288
<TSAndJSSnippet
73-
title="convex/http.js"
89+
title="convex/http.ts"
7490
sourceTS={http}
7591
sourceJS={http}
7692
snippet="router"

0 commit comments

Comments
 (0)