【笔记】Deno的Web服务器
前言
Deno通过oak模块实现Web服务器
创建Web服务器
80:指定端口号
1 | // 引入模块 |
处理请求
获取请求行
获取请求URL
1 | const path = context.request.url.pathname; |
获取请求参数
query
1 | router.get("/", (context) => { |
body
1 | router.post("/", (context) => { |
path
1 | router.get("/:id", (context) => { |
处理响应
设置响应行
设置响应状态码
1 | router.get("/", (context) => { |
设置响应头
1 | router.get("/", (context) => { |
设置响应体
1 | router.get("/", (context) => { |
路由
多个路由
1 | router.post("/", (context) => { |
1 | router |