Request Category:
- POST
- GET
- PUT
- DELETE
- OPTIONS
First of all I, as a developer background I'm used to access coherent processing at me, at first said junction reference mode
- @RequestBody body of data read json
- Parameters in the URL of the read request @RequestParam
- @PathVisiable routing parameters, in order to meet RestFul style
- ... nothing, is generally carried out at the request of distinction: POST Request Form is form, get or RequestParam way, of course, this is not absolute, you have to receive parameters in the URL with POST is also possible
Now it is under the front right way parameter passing:
POST request
Note that I said that the convention is not mandatory rules.
export const saveUser = (data) => {
return axios.request({
url: 'user/user/save',
data,
method: 'post'
})
}
@RequestBody
The following is the time routing process
// 请求拦截
instance.interceptors.request.use(config => {
config.headers.post['Content-Type'] = 'application/json;charset=UTF-8';
config.data = JSON.stringify(config.data);
return config
}, error => {
return Promise.reject(error)
})
FORM Form form
import qs from 'qs';
// 请求拦截
instance.interceptors.request.use(config => {
config.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8';
config.data = qs.stringify(config.data);
return config
}, error => {
return Promise.reject(error)
})
File Upload
// 请求拦截
instance.interceptors.request.use(config => {
config.headers.post['Content-Type'] = 'multipart/form-data';
return config
}, error => {
return Promise.reject(error)
})
These are the treatment for POST requests
GET request
get requests are generally stitching request
export const userList = (params) =>{
return axios.request({
url: 'user/user/list',
params,
method: 'get'
})
}
It does not require any special treatment to
PUT and DELETE requests Request
Basically use @PathVisiable