Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xtreamr/cla-request

Package Overview
Dependencies
Maintainers
11
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xtreamr/cla-request

``` yarn add @xtreamr/cla-request //or npm install @xtreamr/cla-request --save-dev ```

  • 1.0.1
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
11
Weekly downloads
 
Created
Source

Install

yarn add @xtreamr/cla-request 
//or
npm install @xtreamr/cla-request --save-dev

Use:

import Request from '@xtreamr/cla-request'

export const request = new Request()

request.init({ apiUrl: 'www.someapiurl.com' })
request.setBearer({ bearer: 'auth-token' }) // set as authorization header

// - Path: path to build the final end point with apiUrl. If path is: /product/1 -> www.someapiurl.com/product/
// - Options: same options as [vanilla fetch](https://developer.mozilla.org/es/docs/Web/API/Fetch_API) with some changes. Body should be an object and it is using as default the header `’Content-Type': 'application/json’`. Two new options to cache responses: cache and refreshCache (to force refresh cache data).
request.fetch(path, options)

To mock data into development you could configure the request with two paremeters into constructor:

const mockData = {
  // use query, parameters and optionsFetch to mock the api
  // use async functions to not include this code into the final bundle
  '/product/{id}': async ({ 
    query, // query parameters 
    parameters, // path parameters (id in this case), show path '/product/{id}' into mockOptions
    optionsFetch // fetch options { method, mode, headers, body...} https://developer.mozilla.org/es/docs/Web/API/Fetch_API/Using_Fetch
  }) => {
    return {
      id: 1,
      name: 'tv'
    }
  },
  '/products': async () => {
    return [
      {
        id: 1,
        name: 'tv'
      },
      {
        id: 2,
        name: 'computer'
      }
    ]
  },
}

const mockOptions = {
    disabled: false, // if is disable the rest of keys haven't any effect
    delay: 10, // delay of response
    all: false, // all path mock = true
    paths: { // to enable or disable by path
      '/product/{id}': true, // enabled
      '/products': false, // disabled
    },
  },

export const request = new Request({
  mockData, 
  mockOptions
})

FAQs

Package last updated on 10 Aug 2021

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