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

你可能感兴趣的文章
mysql-connector-java各种版本下载地址
查看>>
mysql-group_concat
查看>>
MySQL-redo日志
查看>>
MySQL-【1】配置
查看>>
MySQL-【4】基本操作
查看>>
Mysql-丢失更新
查看>>
Mysql-事务阻塞
查看>>
Mysql-存储引擎
查看>>
mysql-开启慢查询&所有操作记录日志
查看>>
MySQL-数据目录
查看>>
MySQL-数据页的结构
查看>>
MySQL-架构篇
查看>>
MySQL-索引的分类(聚簇索引、二级索引、联合索引)
查看>>
Mysql-触发器及创建触发器失败原因
查看>>
MySQL-连接
查看>>
mysql-递归查询(二)
查看>>
MySQL5.1安装
查看>>
mysql5.5和5.6版本间的坑
查看>>
mysql5.5最简安装教程
查看>>
mysql5.6 TIME,DATETIME,TIMESTAMP
查看>>