@scoir/api

7.0.3 • Public • Published

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) => {
    ...
})

Readme

Keywords

none

Package Sidebar

Install

npm i @scoir/api

Weekly Downloads

454

Version

7.0.3

License

UNLICENSED

Unpacked Size

67.1 kB

Total Files

11

Last publish

Collaborators

  • jasonblanchard
  • alittletonscoir
  • rocky.egawa
  • eric.kertzscoir
  • bonsebas
  • brynkng
  • azragal
  • jhudzik
  • jaymi_johnson
  • jspencer_scoir
  • dkozicki
  • scoir-kevinrathgeber
  • sully-scoir
  • smclaughlin-scoir
  • sbeyers
  • eriksuman
  • robelder
  • scoir-alexr
  • danancook
  • dmscoir
  • cbartlett33
  • jpshrader
  • cmccrory
  • ahagner
  • rrosenthal
  • cellisscoir
  • dbyler_scoir
  • mvannucciscoir
  • kjbillings
  • ccarson_scoir
  • scoir-dev
  • daynek
  • pjohnson11120
  • gakhvledi
  • thos-scoir
  • scoir-devops