mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-05-13 12:37:16 +08:00
35 lines
629 B
TypeScript
35 lines
629 B
TypeScript
import Koa = require("koa");
|
|
import Router = require("koa-router");
|
|
|
|
const app = new Koa();
|
|
|
|
const router = new Router({
|
|
prefix: "/users"
|
|
});
|
|
|
|
router
|
|
.param('id', function(id, ctx, next) {
|
|
next();
|
|
})
|
|
.get('/', function (ctx, next) {
|
|
ctx.body = 'Hello World!';
|
|
})
|
|
.post('/users', function (ctx, next) {
|
|
// ...
|
|
})
|
|
.put('/users/:id', function (ctx, next) {
|
|
ctx.body = ctx.params.id;
|
|
})
|
|
.del('/users/:id', function () {
|
|
// ...
|
|
});
|
|
|
|
router.get('user', '/users/:id', function (ctx) {
|
|
ctx.body = "sdsd";
|
|
});
|
|
|
|
app.use(router.routes());
|
|
app.use(router.allowedMethods());
|
|
|
|
app.listen(3000);
|