mirror of
https://dev.azure.com/tstanciu94/ReverseProxy/_git/ReverseProxy_Frontend
synced 2025-08-05 17:22:36 +03:00
66 lines
1.4 KiB
JavaScript
66 lines
1.4 KiB
JavaScript
import axios from "axios";
|
|
import i18next from "i18next";
|
|
|
|
function getHeaders() {
|
|
return {
|
|
"Content-Type": "application/json",
|
|
"Accept-Language": `${i18next.language}`
|
|
};
|
|
}
|
|
|
|
function internalRequest(url, options) {
|
|
return axios
|
|
.request(url, options)
|
|
.then(res => res.data)
|
|
.catch(function(error) {
|
|
if (error.response && error.response.data) {
|
|
throw {
|
|
...error.response.data,
|
|
message: error.response.data.detail || error.response.data.title
|
|
} || error;
|
|
}
|
|
// The request was made but no response was received
|
|
// `error.request` is an instance of XMLHttpRequest in the browser and an instance of
|
|
// http.ClientRequest in node.js
|
|
throw error;
|
|
});
|
|
}
|
|
|
|
export function post(url, data) {
|
|
const options = {
|
|
method: "post",
|
|
data: JSON.stringify(data),
|
|
headers: getHeaders()
|
|
};
|
|
|
|
return internalRequest(url, options);
|
|
}
|
|
|
|
export function put(url, data) {
|
|
const options = {
|
|
method: "put",
|
|
data: JSON.stringify(data),
|
|
headers: getHeaders()
|
|
};
|
|
|
|
return internalRequest(url, options);
|
|
}
|
|
|
|
export function del(url, data) {
|
|
const options = {
|
|
method: "delete",
|
|
data: JSON.stringify(data),
|
|
headers: getHeaders()
|
|
};
|
|
|
|
return internalRequest(url, options);
|
|
}
|
|
|
|
export function get(url) {
|
|
const options = {
|
|
method: "GET",
|
|
headers: getHeaders()
|
|
};
|
|
return internalRequest(url, options);
|
|
}
|