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

jsonapi-redux-data

Package Overview
Dependencies
Maintainers
3
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonapi-redux-data

Library that makes integration of jsonapi with redux effortless and easy

  • 1.0.17
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
12
decreased by-53.85%
Maintainers
3
Weekly downloads
 
Created
Source

JsonApi Redux Data

JsonApi Redux data is a one stop shop for all your jsonapi needs! Provides methods to make your API call and formats and updates data in the redux store. It joins all of your relations so that accessing it is as easy as entity.relationship

For example if you made an API call to base-url/tasks?include=list, you can access your relationships as easily as tasks[index].list

  • Provides methods to make api calls to your JSONApi compliant backend and updates the redux store as well.

  • Combines the data so it is easily accessible

  • Setup in 3 easy steps

Installation

yarn add jsonapi-redux-data

OR

npm i jsonapi-redux-data

Usage

  • Update the reducers / rootReducers like this

    ...
    import { jsonApiReducer } from 'jsonapi-redux-data'
    ...
    const rootReducer = combineReducers({
        ...,
        api: jsonApiReducer,
        ...
    })
    ...
    
    
  • Create the api client preferrably in the app.js

    ...
    import { createApiClientWithTransform } from 'jsonapi-redux-data'
    ...
    // Create redux store with history
    const initialState = {};
    const store = configureStore(initialState, history);
    ...
    
    createApiClientWithTransform('<base-url>', store)
    ...
    
  • Make api call easily and from anywhere

    ...
    import { getApi } from 'jsonapi-redux-data'
    ...
    
    getApi({ pathname: '<pathname>', include: '<include-string>' })
    ...
    

Example Usage

getApi

  getApi({
    pathname: 'tasks',
    include: 'lists',
    levelOfNesting: 3
  });

Invoking this method will

  • make an api call to base-url/tasks
  • include lists in the response
  • dispatch an action of type SUCCESS_API
  • update the api reducer in the redux store with the formatted response.

API Documentation

getApi

Make a get request and add api response to the redux store.

/**
 * @param  {} requestPayload: {
 *   include: object
 *   filter: object,
 *   pathname: String,
 *   levelOfNesting: number,
 *   transformList: object,
 *   id: String
 * }
 * @param {} api: Custom Api Client instead of the latest created api client
 * @param {} axios: Special axios config
 **/
function getApi (requestPayload, api, axiosConfig)

postApi

Make a post request and add api response to the redux store

/**
 * @param  {} requestPayload: {
 *   include: object
 *   filter: object,
 *   pathname: String,
 *   levelOfNesting: number,
 *   transformList: object,
 *   postData: object
 *   }
 * @param {} api: Custom Api Client instead of the latest created api client
 * @param {} axios: Special axios config
 */
function postApi (requestPayload, api, axiosConfig)

patchApi

Make a patch request and add api response to the redux store

/**
 *
 * @param  {} requestPayload: {
 *   include: object
 *   filter: object,
 *   pathname: String,
 *   levelOfNesting: number,
 *   transformList: object,
 *   patchData: object
 * }
 * @param {} api: Custom Api Client instead of the latest created api client
 * @param {} axios: Special axios config
 *
 * */
function patchApi (requestPayload, api, axios)

deleteApi

Make a delete request and add api response to the redux store


/**
 *
 * @param  {} requestPayload: {
 *   pathname: String,
 *   id: String
 * }
 * @param {} api: Custom Api Client instead of the latest created api client
 * @param {} axios: Special axios config
 *
 * */
function deleteApi (requestPayload, api, axios)

getRequest

GET HTTP REQUEST, uses the apisauce.get underneath the hood.

/**
 * @param  {} pathname: the endpoint path
 * @param  {} include: the jsonapi include string
 * @param  {} filter: the jsonapi filter string
 * @param  {} id: the id of the GET request.
 * @param  {} api: default is getLatestApiClient()
 * @param  {} axiosConfig: custom axiosConfig for this request
 */
function getRequest (pathname, include, filter, id, api, axiosConfig)

postRequest

POST HTTP REQUEST, uses the apisauce.get underneath the hood.

/**
 *
 * @param  {} pathname: the endpoint path
 * @param  {} include: the jsonapi include string
 * @param  {} filter: the jsonapi filter string
 * @param  {} postData: request body
 * @param  {} api: default is getLatestApiClient()
 * @param  {} axiosConfig: custom axiosConfig for this request
 */
function postRequest (pathname, include, filter, postData, api, axiosConfig)

patchRequest

PATCH HTTP REQUEST, uses the apisauce.get underneath the hood.

/**
 * @param  {} pathname
 * @param  {} include: the jsonapi include string
 * @param  {} filter: the jsonapi filter string
 * @param  {} id: the id of the PATCH request.
 * @param  {} patchData: request body
 * @param  {} api: default is getLatestApiClient()
 * @param  {} axiosConfig: custom axiosConfig for this request
 */
function patchRequest (pathname, include, filter, id, patchData, api,axiosConfig)

deleteRequest

DELETE HTTP REQUEST, uses the apisauce.get underneath the hood.

/**
 * @param  {} pathname
 * @param  {} id: the id of the DELETE request.
 * @param  {} api: default is getLatestApiClient()
 * @param  {} axiosConfig: custom axiosConfig for this request
 */
function deleteRequest (pathname, id, api, axiosConfig)

Keywords

FAQs

Package last updated on 30 May 2020

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