您的位置:首页 > Web前端 > Node.js

crossplatform---Nodejs in Visual Studio Code 03.学习Express

2016-07-29 08:12 736 查看
1.开始

下载源码:https://github.com/sayar/NodeMVA

Express组件:npm install express -g(全局安装)

2.ExpressRest

打开目录08_ExpressREST

app.js

现在项目都用html/js了,写个node几行代码搞定json restful,还带web服务器,感觉神清气爽啊!

打开CMD让项目运行起来



3.AdvancedRESTAPI

打开目录12_AdvancedRESTAPI

app.js:初始化Express环境注册路由

routes/api.js :rest api的具体实现代码

app.js中,注册路由代码十分简单

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.

http://www.cnblogs.com/mengkzhaoyun/p/5355796.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: