Files
freeplanet/src/store/Api/Inst-Pao.ts

48 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-11-15 19:48:37 +01:00
import axios, { AxiosInstance, AxiosPromise, AxiosResponse, AxiosInterceptorManager } from 'axios'
async function sendRequest(url: string, lang: string, mytok: string, method: string, mydata: any) {
2018-11-15 19:48:37 +01:00
2019-02-02 20:13:06 +01:00
console.log('sendRequest', method, url, '[', lang, ']')
2019-02-02 20:13:06 +01:00
const authHeader = new Headers()
authHeader.append('content-Type', 'application/json')
authHeader.append('Accept', 'application/json')
2018-11-15 19:48:37 +01:00
authHeader.append('x-auth', mytok)
2019-02-02 20:13:06 +01:00
// authHeader.append('accept-language', lang)
let configInit: RequestInit
if (method === 'GET') {
configInit = {
method: method,
cache: 'no-cache',
mode: 'cors',
headers: authHeader
}
} else if (method === 'DELETE') {
configInit = {
method: method,
cache: 'no-cache',
mode: 'cors',
headers: authHeader
}
} else {
configInit = {
method: method,
cache: 'no-cache',
mode: 'cors',
headers: authHeader
}
if (mydata !== null)
configInit.body = JSON.stringify(mydata)
2018-11-15 19:48:37 +01:00
}
const request: Promise<Response> = fetch(url, configInit)
return request
}
export default sendRequest