- Notifications
You must be signed in to change notification settings - Fork2
Simple and powerful API client. It's extension for native fetch API. No dependencies!
License
marcin-piela/fetching-library
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Simple and powerful fetch API extension. Use request and response interceptors to deal with API.
✅ Zero dependencies
✅ SSR support
✅ Uses Fetch API
✅ Request and response interceptors allows to easily customize connection with API
✅ TypeScript support
✅ Less than 2k minizipped
✅ Simple cache provider - easily to extend
Request and response interceptors allows you to easily customize connection with API (add authorization, refresh token, cache, etc). It uses Fetch API so it can be use in SSR apps (ie. with isomorphic-fetch)
Full documentation is available athttps://marcin-piela.github.io/fetching-library
Run the following from your project root :
npm install fetching-library
or
yarn add fetching-library
import{createClient,cache,requestJsonInterceptor,responseJsonInterceptor,responseTextInterceptor}from'fetching-library';constcache=createCache((action)=>{returnaction.method==='GET';},(response)=>{returnnewDate().getTime()-response.timestamp<100000;},);// Options is not requiredconstclient=createClient({requestInterceptors:[requestJsonInterceptor],responseInterceptors:[responseJsonInterceptor,responseTextInterceptor]cacheProvider:cache,});constaction={method:'GET',endpoint:'/users',};client.query(action).then(response=>{//response.status//response.error//response.errorObject//response.payload});
import{createClient,requestJsonInterceptor,responseJsonInterceptor}from'fetching-library';constrequestHostInterceptor:host=>client=>asyncaction=>{return{ ...action,endpoint:`${host}${action.endpoint}`,};};constclient=createClient({requestInterceptors:[requestJsonInterceptor,requestHostInterceptor('http://example.com')],responseInterceptors:[responseJsonInterceptor]cacheProvider:cache,});constaction={method:'GET',endpoint:'/users',};client.query(action).then(response=>{//response.status//response.error//response.errorObject//response.payload});
Fell free to open PRs and issues to make this library better !
When making a PR, make sure all tests pass. If you add a new feature, please consider updating the documentation or codesandbox examples. Thank you!
fetching-library is licensed under theMIT license.
About
Simple and powerful API client. It's extension for native fetch API. No dependencies!
Topics
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors2
Uh oh!
There was an error while loading.Please reload this page.
