主要依靠接口名称和请求类型而在restful设计中,它们应该是这样的:
接口名:localhost:8080/articles 类型:get 功能:获取文章信息
接口名:localhost:8080/articles 类型:post 功能:添加新文章
接口名:localhost:8080/articles 类型:delete 功能:删除文章
接口名:localhost:8080/articles 类型:put 功能:编辑文章
RESTful设计是:
1.通过URL设计资源。接口名一般都是名词,不包含动词。
2.请求方式(get,post,delete,put)决定资源的操作类型
示例:
const express = require('express')
const app = express();
app.get('/articles',(req,res)=>{
res.send('获取')
})
app.post('/articles',(req,res)=>{
res.send('添加')
})
app.delete('/articles',(req,res)=>{
res.send('删除')
})
app.put('/articles',(req,res)=>{
res.send('编辑')
})
app.listen(8080,()=>{
console.log(8080);
})