Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/silverboyir/silver-request
https://github.com/silverboyir/silver-request
Last synced: 16 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/silverboyir/silver-request
- Owner: silverboyir
- License: apache-2.0
- Created: 2019-06-19T18:39:53.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T12:55:25.000Z (almost 2 years ago)
- Last Synced: 2024-09-27T06:34:29.426Z (about 2 months ago)
- Language: TypeScript
- Size: 2.66 MB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SilverRequest
A Fetch Wrapper with cache support that works with Redux
## Getting Started
```
import SilverRequest from "silver-request";new SilverRequest(dispatch)
.setUrl('http://github.com')
.setEvent('Github Loaded')
.send();
```### Installing
using yarn
```
yarn add silver-request
```
npm
```
npm install silver-request
```
## Running the testssimply run
```
yarn test
```## Usage
| method | type | default | Description |
| --- | --- | --- | --- |
| `setLogger` | function | null | set a function for loggin eg console.log
| `setRunOnSuccess` | function | null | set a function to run on successful request and to call this method is useful when you want plugin call desire event on successful request
| `setOnSuccess` | function or object | function | set a function to be called after receiving respond , this will override calling event
| `setOnError` | function | function | set a function to be called after error happen
| `setMethod` | string | GET | set request type method
| `setIsCachable` | boolean | false | is request is cachable or not
| `setUrl` | string | null |
| `setEvent` | string | null | the event name (Redux Event) that will be fired after successful request
| `setData` | object | null | the data that will be sent by POST request
| `setNeedLoading` | boolean | false |
| `addAdditionalHeader` | object | null | adding additional header to request
| `setAdditionalHeader` | object | null | set additional header to request
| `setCacheTime` | integer | 30*60*1000 |
| `setIsHardRefresh` | boolean | false | if true , it will ignore existing cache , but will cache the reponse
| `send` | | | call this method to send the request## Static Properties
this properties will be applied to all request , set them in initializing you application
| name | type | default | Description |
| --- | --- | --- | --- |
| `additionalHeader` | object | object | adding token for example
| `lang` | string | en_US |
| `cacheHandler` | Object | LocalStorageCacheHandler |
| `cacheTime` | Integer | 30*60*1000 |
| `globalOnSuccess` | function | null |
| `globalOnError` | function | null |
| `languageFile` | Object | Object |## TODO
* writing more test
* writing more cache adapter
* adding canceling request ability