add pathParams

This commit is contained in:
2023-05-11 06:46:41 +02:00
parent 5da902fb3b
commit 129366c087
2 changed files with 147 additions and 59 deletions

View File

@@ -2,12 +2,14 @@ import { Status } from "https://deno.land/std@0.186.0/http/http_status.ts";
import { HTTPServer } from "../http_server.ts";
const httpServer = new HTTPServer();
httpServer.add("GET", "/", (_req, rep) => {
httpServer.add("GET", "/", (req, rep) => {
rep.status(Status.Teapot)
.header("working", "true")
.type("application/json")
.cookie("working", "true");
console.log(_req.cookie("working"));
console.log(req.cookie("working"));
return JSON.stringify(
{
code: Status.Teapot,
@@ -17,6 +19,19 @@ httpServer.add("GET", "/", (_req, rep) => {
2,
);
});
httpServer.add("GET", "/api/user/:userId", (req, rep) => {
rep.status(Status.Teapot)
.type("application/json");
return JSON.stringify(
{
code: Status.Teapot,
message: `UserID is ${req.pathParams["userId"]}`,
},
null,
2,
);
});
httpServer.listen({
port: 8080,
staticLocalDir: "/static",