博客
关于我
koa-router
阅读量:529 次
发布时间:2019-03-08

本文共 897 字,大约阅读时间需要 2 分钟。

const Koa = require("koa");const Router = require("koa-router");let app = new Koa();let router = new Router();router("/",async ctx=>{       // 会将 / 和 /index的请求,返回同一页面    ctx.redirect("/index");    ctx.body = "主页";});router.get("/datail",async ctx=>{       ctx.body = "详情页"});router.get("/getData",async ctx=>{       // let indexData = fs.readFile("index.html");    let indexData = "我是模拟数据";    // ctx.body = {       //     indexData    // };    ctx.render("/index2",{           indexData    });});// RESTful : 接口设计原则// post / get// 错误做法// localhost:8000/adduser// localhost:8000/deletuser// localhost:8000/updateuser// localhost:8000/getuser// 正确做法// localhost:8000/uesr  请求方式 get 获取// localhost:8000/uesr  delete 删除// localhost:8000/uesr  put 更新// localhost:8000/uesr  post 添加/*    程序或者应用的事物都应该被抽象为资源    每个资源对应唯一的URI(uri是统一资源标识符)    使用统一接口对资源进行操作    对资源*/app.use(router.routes());app.listen(8888)

转载地址:http://hawiz.baihongyu.com/

你可能感兴趣的文章
memcache、redis原理对比
查看>>
memset初始化高维数组为-1/0
查看>>
Metasploit CGI网关接口渗透测试实战
查看>>
Metasploit Web服务器渗透测试实战
查看>>
Moment.js常见用法总结
查看>>
MongoDB出现Error parsing command line: unrecognised option ‘--fork‘ 的解决方法
查看>>
mxGraph改变图形大小重置overlay位置
查看>>
MongoDB学习笔记(8)--索引及优化索引
查看>>
MQTT工作笔记0009---订阅主题和订阅确认
查看>>
ms sql server 2008 sp2更新异常
查看>>
MS UC 2013-0-Prepare Tool
查看>>
msbuild发布web应用程序
查看>>
MSB与LSB
查看>>
MSCRM调用外部JS文件
查看>>
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>