博客
关于我
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/

你可能感兴趣的文章
MSCRM调用外部JS文件
查看>>
MSEdgeDriver (Chromium) 不适用于版本 >= 79.0.313 (Canary)
查看>>
MsEdgeTTS开源项目使用教程
查看>>
msf
查看>>
MSSQL数据库查询优化(一)
查看>>
MSSQL日期格式转换函数(使用CONVERT)
查看>>
MSTP多生成树协议(第二课)
查看>>
MSTP是什么?有哪些专有名词?
查看>>
Mstsc 远程桌面链接 And 网络映射
查看>>
Myeclipse常用快捷键
查看>>
MyEclipse用(JDBC)连接SQL出现的问题~
查看>>
myeclipse的新建severlet不见解决方法
查看>>
MyEclipse设置当前行背景颜色、选中单词前景色、背景色
查看>>
myeclipse配置springmvc教程
查看>>
MyEclipse配置SVN
查看>>
MTCNN 人脸检测
查看>>
MyEcplise中SpringBoot怎样定制启动banner?
查看>>
MyPython
查看>>
MTD技术介绍
查看>>
MySQL
查看>>