npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

redux-api-http

v2.0.1

Published

calling api's using redux architecture

Downloads

13

Readme

redux-api-http

Library to send http request while following redux architecture.

Installation

npm install redux-api-http --save

Importing the service

it can be imported as a reference of class object

import {asyncService} from 'redux-api-http';

or, as the class itself

import AsyncService from 'redux-api-http';

in the first case we can import reducers also as a constant import

import {asyncService, apiReducer} from 'redux-api-http';

for the second case we need to fetch the reducer by creating object of class

import AsyncService from 'redux-api-http';

AsyncService service = new AsyncService();
let reducer = service.getReducer();

This service exposes two major function for users dispatch method for sending api request and remove method for removing api response from the store (the later functionality is useful in some cases)

method signature for dispatch

dispatch = function(key, api, method, data, headers) {
	// some defination
}

here key is the unique api identifier used to distinguish api data in store from one another. This package also export a constant object for method field

apiMethod = {
	GET: 'get',
	POST: 'post',
	PUT: 'put', 
	DELETE: 'delete'
}

to import it

import {apiMethod} from 'redux-api-http';

method signature for remove

remove = function(key) {
	// some defination
}

here key is the same key which we used in dispatch method to uniquely identify the api and distinguish its state in the store.

generalised usage

import {asyncService} from 'redux-api-http';

let data = {
	key1: 'value',
	key2: 'value'
};
let header = {
	header1: 'value',
	header2: 'value'
};

asyncService.dispatch('myApiKey', 'http://mySampleApi.com/service1', 'get', data, header);

asynService.remove('myApiKey');

Example


// Container Component
import React from 'react';
import ReactDOM from 'react-dom';
import {combineReducers, createStore} from 'redux';
import {Provider} from 'react-redux';
import {apiReducer} from 'redux-api-http';
import DummyComponent from '<path>';

let reducers = combineReducers({
	'apiReducer': apiReducer
});
let store = createStore(reducers);

class SomeComponent extends React.Component {
	render() {
		return (
			<Provider store={store}>
				<DummyComponent />
			</Provider>
		);
	}
}
ReactDOM.render(<SomeComponent />, document.getElementById('container'));

// Dummy Component
import React from 'react';
import {asyncService, apiMethod} from 'redux-api-http';

class DummyComponent extends React.Component {
	componentDidMount() {
		this.props.dispatch(asyncService.dispatch('key','http://someapi.com/service', apiMethod.GET, {}, {}));
	}
	
	render() {
		console.log(this.props.someProp);
		return (
			<div>
				dummy component
			</div>
		);
	}
}

// here apiReducer is used because we register our reducer with this name in the above code
let mapStateToProps = (state) => ({
	someProp: state.apiReducer.key
})
export default connect(mapStateToProps)(DummyComponent);