Http Api
basic example to use the http-api
const req = {
action: "POST", // 'GET' | 'POST' | 'PUT' | 'DELETE';
url: `my-request-url`,
// allows to set custom headers if needed
headers: [],
resolve: (res) => {
// optional callback func for this req.
},
// the type of the response -> defaults to json
responseType: 'json', // 'json' | 'text' | 'arraybuffer' | 'blob';
// the body if needed
body: {
}
}
fyzUtils.httpApi.executeRequestsAsync([req], (response) => {
// called after all requests are executed
})
Use the http-api in combination with connector-api
// basic setup
const CONNECTOR = window.env.connectorApi;
const url = window.location.href;
let protocoll = url.split("://");
const secure = protocoll && protocoll.length == 2 && protocoll[0].includes("s") ? 's' : '';
const BASE_URL_REST = `http${secure}://${CONNECTOR}`;
const req = {
action: "POST", // 'GET' | 'POST' | 'PUT' | 'DELETE';
url: `${BASE_URL_REST}/api/data/connect`,
headers: [],
environment: {},
resolve: (res) => {
// optional callback func for this req.
},
responseType: 'blob', // 'json' | 'text' | 'arraybuffer' | 'blob';
body: {
Configuration: {
Route: 'some-sample',
Authentication: true, // true / false
AuthenticationType: 'JWT' // JWT / BASIC / API_KEY
Method: 'POST' // GET / PUT / POST / DELETE / PATCH
},
/**
* Conating information send as Body to the reciving endpoint -> here to some-sample
*/
ApiConfig: { assetId: '65661401d2f923d89f5e81fd', before: '2023-12-31T14:08:00.000Z', after: '2023-12-01T14:08:00.000Z' }
}
}
fyzUtils.httpApi.executeRequestsAsync([req], (response) => {
// called after all requests are executed
})