Add DRP document
This commit is contained in:
45
src/utils/http.js
Normal file
45
src/utils/http.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const http = {
|
||||
async request(method, url, data, headers = {}) {
|
||||
try {
|
||||
const defaultHeaders = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
|
||||
headers = Object.assign(defaultHeaders, headers);
|
||||
|
||||
const options = {
|
||||
method: method,
|
||||
body: JSON.stringify(data),
|
||||
headers,
|
||||
}
|
||||
|
||||
if (method === 'GET') {
|
||||
delete options.body;
|
||||
}
|
||||
|
||||
return await fetch(url, options)
|
||||
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
},
|
||||
|
||||
async get(url, headers = {}) {
|
||||
return await this.request('GET', url, null, headers);
|
||||
},
|
||||
|
||||
async post(url, data, headers) {
|
||||
return await this.request('POST', url, data, headers);
|
||||
},
|
||||
|
||||
async put(url, data, headers) {
|
||||
return await this.request('PUT', url, data, headers);
|
||||
},
|
||||
|
||||
async delete(url, data, headers) {
|
||||
return await this.request('DELETE', url, data, headers);
|
||||
},
|
||||
}
|
||||
|
||||
export default http;
|
Reference in New Issue
Block a user