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

redux-swagger-client

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

redux-swagger-client

Swagger middleware for Redux.

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
47
increased by123.81%
Maintainers
3
Weekly downloads
 
Created
Source

Redux Swagger Client

Swagger middleware for redux

About

This is an attempt to add asynchronous swagger api calls to redux. It works by dispatching an action that includes the field swagger that takes a function and passes the swagger client element to that function. If the swagger spec has not yet been parsed, the action will get queued.

Installation

note: This module requires redux-thunk Github:

npm install --save github:noh4ck/redux-swagger-client

Package pending:

npm install --save redux-swagger-client

To enable Redux Swagger-client, use applyMiddleware():

import { createStore, applyMiddleware } from 'redux'
import swaggerClient from 'redux-swagger-client'
import thunk from 'redux-thunk'

const store = createStore(
  rootReducer,
  applyMiddleware([
    thunk,
    swaggerClient({url:'http://petstore.swagger.io/v2/swagger.json'})
  ])
);

Usage

function fetchPet() {
  return { 
    types: ["FETCH_PETS", "FETCH_PETS_SUCCESS", "FETCH_PETS_FAILED"],
    swagger: api => api.pet.findPetsByStatus({status: 'available'})
  }
}

store.dispatch(fetchPets())

Note, it's also possible to dispatch functions:


function fetchPets_request(json) {
  return {
    type: 'FETCH_PETS',
    receivedAt: Date.now()
  }
}
function fetchPets_success(json) {
  return {
    type: 'FETCH_PETS_SUCCESS',
    pets: json.result.body,
    receivedAt: Date.now()
  }
}
function fetchPets_failure(json) {
  return {
    type: 'FETCH_PETS_FAILED',
    pets: null,
    error,
    receivedAt: Date.now()
  }
}

function fetchPet() {
  return {
    actions: [fetchPets_request, fetchPets_success, fetchPets_failure],
    swagger: api => api.pet.findPetsByStatus({status: 'available'})
  }
}

store.dispatch(fetchPets())

Keywords

FAQs

Package last updated on 10 Sep 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

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