Gathering detailed insights and metrics for easy-redux-http-call
Gathering detailed insights and metrics for easy-redux-http-call
Gathering detailed insights and metrics for easy-redux-http-call
Gathering detailed insights and metrics for easy-redux-http-call
npm install easy-redux-http-call
Typescript
Module System
Min. Node Version
Node Version
NPM Version
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
2
4
30
Created to make http call easy
1npm install --save easy-redux-http-call
or
1yarn add easy-redux-http-call
The CreateBase helps you to make HTTP calls easier. It's like having a special helper who knows how to talk to websites and get information for us. We can use it to ask http server for data without having to do all the setup work ourselves.
To use CreateBase, we need to give it some information. Here's an example:
1const main = new CreateBase({ 2 store: store, // global store 3 baseApiUrl: "https://dummy.restapiexample.com/api/v1", // API Endpoint 4 httpFn: (data) => window.fetch[data.method](data.endpoint, data.params).then( 5 (res) => res.data 6 ), // HTTP Reqeust function 7});
Create base will return your 2 method. this method uses default configuration from the createBase class. you can override this configuration at any time you want.
Now, we have main with below methods
As metion before it let's you create instance to make your API call. surely you have multiple api's in your project. so for that you can use many time as you want. let's create first api instance
1export const AI_updateTourConfig = main.createInstance({ 2 endpoint: "/employees", // api endpoint 3 method: "get", // http metion 4 reducer: "user", // reducer name 5 reduxKey: "userDetail", // key inside you reducer 6 action: "GET_USER_DETAIL", 7 onSuccess: (data) => data, 8});
createInstance will generate new instance and store it into AI_updateTourConfig. This instance has method "call" which makes the actual HTTP request.
createListInstance use to create listing instance to make HTTP call with 2 methods(updateAction, deleteAction). This 2 method will help you to perform update and delete of records from the redux. this functions can be directly call from Socket.
1export const AI_BranchUserList = main.createListInstance({ 2 endpoint: GET_BRANCH_USER_LIST_ENDPOINT, 3 method: "get", 4 id: "product_id", 5 reducer: "product", 6 reduxKey: "productList", 7 action: "GET_PRODUCT_LIST", 8 onSuccess: (data) => data, 9 middleware: myMiddleWare, 10});
Auto generated method will automatically update or remove records from given information at configuration time.
Middleware in create instance is used to perform option on different state of the execution. All the callback of middleware are as bellow
Used to bind all the dynamic action to specified reducer. This will allow easy-reduc-http-call to handle state update for different situation.
const newUserReducer = bindReducer(configReducer, { key: "userReducer" });
Above code will be result as new reducer from the give reducer called newUserReducer. which can be used in combineRedux or directly used to create store.
use useInstance hook which help you get easily fetch state of current HTTP request. you don't have to make any configuation.
const reduxState = useInstance(httpInstance);
reduxState contain value of given(httpInstance) instance state from the redux.
MIT © prafuliihglobal
No vulnerabilities found.
No security vulnerabilities found.