Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Simple and powerful API client. It's extension for native fetch API. No dependencies!

License

NotificationsYou must be signed in to change notification settings

marcin-piela/fetching-library

Repository files navigation

Simple and powerful fetch API extension. Use request and response interceptors to deal with API.

Watch on GitHubStar on GitHubTweet


Build StatusversiondownloadsMIT LicensePRs WelcomeCode of ConductGzip badgecodecov

✅ 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


fetching-library

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)

Documentation

Full documentation is available athttps://marcin-piela.github.io/fetching-library

Installation

Run the following from your project root :

npm install fetching-library

or

yarn add fetching-library

Short example of use with caching

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});

Example of request interceptor

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});

Do you want to use it in react app?

Checkreact-fetching-library

Contributing

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!

License

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp