Deno 小小实战 Rest Todo API
Oak 简介
import { Application } from 'https://deno.land/x/oak/mod.ts';
const app = new Application();
app.use(ctx => {
ctx.response.body = "hello Deno!"
})
await app.listen({ port: 8080 });import { Application } from 'https://deno.land/x/oak/mod.ts';
const app = new Application();
// Logger
app.use(async (ctx, next) => {
await next();
const rt = ctx.response.headers.get("X-Response-Time");
console.log(`${ctx.request.method} ${ctx.request.url} - ${rt}`)
})
// Timing
app.use(async (ctx, next) => {
const start = Date.now();
await next();
const ms = Date.now() - start;
ctx.response.headers.set("X-Response-Time", `${ms}ms`);
})
// Hello World
app.use(ctx => {
ctx.response.body = "Hello World"
})
await app.listen({ port: 8080 })Oak 实战
需求分析
初始化项目结构
最后更新于