Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kaankucukx/redux-saga-service-wrapper
Redux Saga Service-Wrapper
https://github.com/kaankucukx/redux-saga-service-wrapper
Last synced: 2 days ago
JSON representation
Redux Saga Service-Wrapper
- Host: GitHub
- URL: https://github.com/kaankucukx/redux-saga-service-wrapper
- Owner: kaankucukx
- Created: 2020-10-04T23:27:14.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2020-10-11T05:43:37.000Z (about 4 years ago)
- Last Synced: 2024-04-28T20:43:38.621Z (7 months ago)
- Language: TypeScript
- Size: 170 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Redux-Saga Service Wrapper
Redux-Saga Service Wrapper is an approach that allows you to manage your services with only one **Saga** and call separate **action** accordingly, the rest is under your control! Perform anything you want.Yes, you can use **serviceWrapperSaga** for your all service calls and manage your response for error and success cases. We use **[Map object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map)** for handling errors.
```javascript
export const endpoints = {
filter: () => `anyServicePath`
}
export const getService: () => Promise = () => axios.get(endpoints.filter());
export const postService: (body: any) => Promise = (body: any) => axios.post(endpoints.filter(), body);
```
## GET Service Call
```javascriptfunction* getServiceSaga({ searchQuery }) {
try {
const { filter } = yield serviceWrapperSaga(getService)
//....
} catch (e) {
console.log(e);
}
}
```## POST Service Call
```javascriptfunction* postServiceSaga({ searchQuery }) {
try {
const { filter } = yield serviceWrapperSaga(postService, {test: 'TEST'})
//....
} catch (e) {
console.log(e);
}
}
```
## Handling Errors
```javascript
Loading .. ;)
```