Socket
Socket
Sign inDemoInstall

@scoir/api

Package Overview
Dependencies
2
Maintainers
36
Versions
23
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @scoir/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.


Version published
Weekly downloads
454
increased by70.68%
Maintainers
36
Install size
117 kB
Created
Weekly downloads
 

Readme

Source

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

FAQs

Last updated on 24 Jan 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc