New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@contactlab/appy

Package Overview
Dependencies
Maintainers
6
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@contactlab/appy

Fetch API the Contactlab way

  • 0.2.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30
decreased by-80.39%
Maintainers
6
Weekly downloads
 
Created
Source

Appy Build Status

Fetch API the Contactlab way

This package is statically typed using Flow

Install

  $ yarn add @contactlab/appy

Use

Request

  import {request} from '@contactlab/appy';

  const options = {
    // request options
  };

  // request :: (String, String, ?Object) => Promise<Object>
  request('GET', 'https://my.api.com/me', options)
    .then(handleResponse)
    .catch(handleError)

Request options:

  • There is no need to specify a method key, it is overridden by the method argument passed to request().
  • The default mode is set to "cors".
  • The body content gets stringified, so objects are accepted

request returns a Promise. For both Success and Reject cases the return type is:

Promise<{
  status: string,
  payload: Object | {message: string}
}>

Api

Internally uses the request().

  import {api} from '@contactlab/appy';

  const config = {
    baseUri: 'https://my.api.com',
    id: 'module_id',
    version: '1.0.0'
  }
  const options = {
    // request options
  };

  // api :: (Object) => (String, String, String, ?Object) => Promise<Object>
  const myFetch = api(config);
  myFetch('GET', '/me', 'myToken', options)
    .then(handleResponse)
    .catch(handleError)

Request options as above apart from the headers:

  • If not overwritten by the headers passed in, "Accept" and "Content-type" are set to "application/json".
  • "Authorization" is set by the token argument.
  • "Contactlab-ClientId" is set by the id key of the configuration.
  • "Contactlab-ClientVersion" is set by the version key of the configuration.

api at the second call returns the request Promise type.

Unless a configuration error occurs, in that case the return type will be:

Promise<{
  error: string
}>

Test

  $ yarn test

FAQs

Package last updated on 31 Jan 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc