CMU Coding Bootcamp
1import express from "express";
2
3const app = express();
4
5app.get("/books/:id", async (req, res) => {
6 const { id } = req.params;
7 const book = await fetch(`localhost:5713/books/${id}`);
8 const body = await book.json();
9 res.send(body);
10});
11
12app.get("/tasks/:id", async (req, res) => {
13 const { id } = req.params;
14 const task = await fetch(`localhost:5713/tasks/${id}`);
15 const body = await task.json();
16 res.send(body);
17});
18
19app.all("/*splat", (req, res) => {
20 res.status(404).send("Not Found");
21});
22
23app.listen(3000, () => {
24 console.log("Server started on port 3000");
25});