get请求方式
GET请求会向数据库发索取数据的请求,从而来获取信息,该请求就像数据库的select操作一样,只是用来查询一下数据,不会修改、增加数据,不会影响资源的内容,即该请求不会产生副作用。无论进行多少次操作,结果都是一样的。
服务器
// 传统的URL
app.get('/axios', (req, res) => {
res.send('axios get 传递参数' + req.query.id)
})
// Restful 的URL
app.get('/axios/:id', (req, res) => {
res.send('axios get(Restful) 传递参数' + req.params.id)
})
app.get('/data', (req, res) => {
res.send('Hello World !')
})
客户端
axios.get('http://localhost:3000/adata').then(function (ret) {
console.log(ret.data);
});
// 传统URL 只需要
axios.get('http://localhost:3000/axios?id=123').then(function (res) {
console.log(res.data);
});
axios.get('http://localhost:3000/axios/123').then