Node学习记录: koa
前端用koa模拟动态接口
实战教程(6)使用fetch有一部分讲解
npm install koa koa-body koa-router --save-dev
var app = require('koa')(); var router = require('koa-router')(); var koaBody = require('koa-body')(); router.get('/', function *(next) { this.body = 'hello koa !' }); router.get('/api', function *(next) { this.body = 'test data' }); router.get('/api/1', function *(next) { this.body = 'test data 1' }); router.get('/api/2', function *(next) { this.body = { a: 1, b: '123' } }); router.post('/api/post', koaBody, function *(next) { console.log(this.request.body) this.body = JSON.stringify(this.request.body) }); app.use(router.routes()) .use(router.allowedMethods()); app.listen(3000);
相关推荐
往后余生 2020-09-17
lzccheng 2020-09-06
yanyongtao 2020-11-02
webgm 2020-08-16
lert0 2020-08-16
80447704 2020-06-09
LorenLiu 2020-06-07
无缘公子 2020-02-02
LorenLiu 2020-01-31
LorenLiu 2020-01-30
80447704 2020-01-30
苏莉koa 2020-01-29
Qimingweikun 2020-01-28
80447704 2020-01-02
byourb 2020-01-04
80447704 2019-12-24