-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
36 lines (28 loc) · 848 Bytes
/
Copy pathindex.js
File metadata and controls
36 lines (28 loc) · 848 Bytes
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
35
36
import { http } from "@ampt/sdk";
import express, { Router } from "express";
// Create express app and router
const app = express();
const api = Router();
// Mount api to /api base route
app.use("/api", api);
// Hello route: /api/hello
api.get("/hello", (req, res) => {
return res.status(200).send({ message: "Hello from the public api!" });
});
// Greet route: /api/greet/:name
api.get("/greet/:name", (req, res) => {
const { name } = req.params;
if (!name) {
return res.status(400).send({ message: "Missing route param for `name`!" });
}
return res.status(200).send({ message: `Hello ${name}!` });
});
// Post route: /api/submit
api.post("/submit", async (req, res) => {
return res.status(200).send({
body: req.body,
message: "You just posted data",
});
});
// Expose the app to the Internet
http.node.use(app);