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

cd-fetch-model

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cd-fetch-model

A helper which extends fetch with powerful methods for simplifying interaction with RESTful APIs.

0.6.0
latest
npm
Version published
Weekly downloads
0
-100%
Maintainers
1
Weekly downloads
 
Created
Source

Fetch Wrapper

This library provides a set of simple, easy to use wrappers around native fetch. It also provides a convenient Model/API interface which allows you to avoid boilerplate communication code for simple/standardised API endpoints.

Note this is not a polyfill or fetch replacement — it's a set of convenience methods to avoid repetitive configs and parsing.

Installation

Install with Yarn

yarn add cd-fetch-model

Or with NPM

npm install --save cd-fetch-model

Please Note: You'll need to be registered to https://npm.customd.com to access this module. To do this, run;

npm config set registry https://npm.customd.com

Basic Usage

The wrappers main function is to provide you with a Model class that simplifies connections to a Zon RESTful API.

import FetchApi from 'cd-fetch-model'

class ResultsModel extends FetchApi {

    const api_url = Site.api_url + "results";
}

export default ResultsModel

You may find situations where it's useful to overload the default methods or provide defaults.


class ResultsModel extends FetchApi {

    const api_url = Site.api_url + "results";

    /**
     * Overload arguments with a set of defaults.
     */
    getWhere( where, sort = '-created', limit = 25, offset = 0) {

        super.getWhere(where, sort, limit, offset)
    }
}

These classes can then be imported into your action creators and used, E.g.,

import Results from 'api/Results'

Results.getWhere({ foo: 'bar' }).then(() => {

    /** do something **/
})

Direct acces to helper methods

You can also implement custom methods accessing fetch helper methods directly, as required.

import { fetchGet, fetchParams } from 'cd-fetch-model'


export default const getWhere = ( where, sort = '-created', limit = 25, offset = 0 ) => {

    const params = fetchParams({
        ...where,
        sort,
        limit,
        offset
    })

    return fetchGet('https://www.example.com/api/v1/results?'+params)
}

FAQs

Package last updated on 14 Dec 2017

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