@scoir/api
v7.0.3
Published
This utility handles standard HTTP verb requests in JavaScript for use in an authenticated application. It also provides mechanisms to get PDF, CSV, & Zip files.
Downloads
767
Maintainers
Keywords
Readme
Api
This utility handles standard HTTP verb requests in JavaScript for use in an authenticated application. It also provides mechanisms to get PDF, CSV, & Zip files.
Usage
initialize api instance
Pass in the fall back url function that will be used when a route is "unauthorized";
import apiFactory from '@scoir/api';
const fallBackUrlFn = () => '/login';
const api = apiFactory(fallBackUrlFn);
// use the api object
api instance
Use the instance to issue HTTP verbs
import apiFactory from '@scoir/api';
const fallBackUrlFn = () => '/login';
const api = apiFactory(fallBackUrlFn);
api.get(url).then(() => {
...
})
api.post(url, payload).then(() => {
...
})
api.put(url, payload).then(() => {
...
})
api.delete(url).then(() => {
...
})
api.patch(url, original, diff).then(() => {
...
})
getZip
Use to get a zip file at a given url.
returns new Blob([data], {type: 'application/zip'})
.
import apiFactory, { getZip } from '@scoir/api';
getZip(url).then((zipBlob) => {
...
})
getCSV
Use to get a CSV file at a given url. returns file blob.
import apiFactory, { getCSV } from '@scoir/api';
getCSV(url).then((CsvFileBlob) => {
...
})
getPdf
Use to get a Pdf file at a given url. returns byte array.
import apiFactory, { getPdf } from '@scoir/api';
getPdf(url).then((pdfByteArray) => {
...
})