generated from ampt-templates/ampt-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
34 lines (26 loc) · 830 Bytes
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// **
// * @ampt/api is experimental and subject to change. DO NOT use this for production apps.
// * Please report any bugs to Discord!
// **
import { api } from "@ampt/api";
const publicApi = api("public").router("/api");
publicApi.get("/hello", async (event) => {
return event.status(200).body({ message: "Hello from the public api!" });
});
publicApi.get("/greet", async (event) => {
const { query } = event.request;
const name = query.get("name");
if (!name) {
return event
.status(400)
.body({ message: "Missing query param for `name`!" });
}
return event.status(200).body({ message: `Hello ${name}!` });
});
publicApi.post("/submit", async (event) => {
const body = await event.request.body();
return event.status(200).body({
body,
message: "You just posted data",
});
});