@hyper.software/backend-api-client
v1.0.19
Published
Hyper Software Backend API client
Readme
Package to quickly build a service to service REST client
Usage:
const client = new BackendApiClient({
baseURL: GLOBAL_CONFIG.baseUrl,
serviceName: '[[FILE_STORAGE-CLIENT]]',
auth: {
apiKey: 'API_KEY',
},
});
// Do a request protected by bearer token
const getProducts = async (fullSearch: string): Promise<AxiosResponse<Product[]>> =>
client.get(`/products?${qs.stringify({ fullSearch })}`, {
auth: {
userAccessToken: 'TOKEN',
},
partner: {
subdomain: 'acme',
},
});
// Create a file with multipart-form-data
new Promise<AxiosResponse<i.IFile>>((resolve, reject) => {
const fd = new FormData();
const { name, partner } = options;
fd.append('file', buffer, name);
fd.pipe(
concat({ encoding: 'buffer' }, (payload) =>
client
.post(`/file`, payload, {
partner,
axiosConfig: {
headers: fd.getHeaders(),
},
})
.then(resolve)
.catch(reject),
),
);
});
// Get a stream file
client.get(`/file/:id`, {
axiosConfig: {
responseType: 'stream',
},
});