crossplatform---Nodejs in Visual Studio Code 03.学习Express
1.开始
下载源码:https://github.com/sayar/NodeMVA
Express组件:npm install express -g(全局安装)
2.ExpressRest
打开目录08_ExpressREST
app.js
1 2 3 4 5 6 7 8 |
|
现在项目都用html/js了,写个node几行代码搞定json restful,还带web服务器,感觉神清气爽啊!
打开CMD让项目运行起来
1 2 |
|
3.AdvancedRESTAPI
打开目录12_AdvancedRESTAPI
app.js:初始化Express环境注册路由
routes/api.js :rest api的具体实现代码
app.js中,注册路由代码十分简单
1 2 3 4 5 6 7 8 |
|
routes/api.js中对每个api后的url按GET\PUT\POST\DELETE分别处理
Resource | GET | PUT | POST | DELETE |
Collection URI, such as http://api.example.com/v1/dogs/ | List all the dogs | Replace all the dogs with a new collection of dogs. | Create a new dog in the collection. | Delete the entire dog collection. |
Element URI, such as http://api.example.com/v1/dog/1 | Get a specific dog. | Replace a dog in the collection with another dog. | Not used. | Delete the dog from the collection. |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
|
http://www.cnblogs.com/mengkzhaoyun/p/5355796.html