oak
概要
Router
code:typescript
export {
Application,
Router,
const app = new Application();
const router = new Router({ prefix: "/api" });
router.get("/feeds", (ctx) => getFeeds(ctx));
router.post("/feeds", (ctx) => addFeed(ctx));
app.use(router.routes());
app.use(router.allowedMethods());
const port = 3000;
await app.listen({ port });
HTTPエラーの取扱について
Context#throw
Context#assert
code:typescript
const body = await ctx.request.body();
ctx.assert(body.type === "json", 400); // 一つ目の引数がfalseなら400エラーを返却します