npm install --save isomorphic-fetch
import fetch from 'isomorphic-fetch';
const apiUrl = 'https://api.dfend.app';
const headers = {
Accept: 'application/json',
'Content-Type': 'application/json',
'X-Api-Key': process.env.DFEND_SECRET_KEY
};
const fetchJson = async (method = 'POST', endpoint, data = {}) => {
const res = await fetch(`${apiUrl}/${endpoint}`, {
headers,
method,
body: JSON.stringify(data),
credentials: 'omit'
});
return res.json();
};
const post = (endpoint, data = {}) => {
return fetchJson('POST', endpoint, data);
};
const get = async (endpoint, data = {}) => {
return fetchJson('GET', endpoint, data);
};
export const identity = {
get: (data = {}) => get('identity', data),
post: (data = {}) => post('identity', data)
};
export const signal = {
post: (data = {}) => post('signal', data)
}