Skip to content

evan-liu/fetch-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fetch-queue

Build Status Code Coverage

A http request queue based on fetch() API.

Why

REST APIs often require a lot of http requests to fetch data for complicated clients like mobile apps or single page web applications, which lead to bad user experiences, especially with HTTP 1.1 max connections per hostname limitation. GraphQL is Facebook's answer to this problem (and others), while fetch-queue is trying to help those stuck with REST API servers.

How

For example, you can create one fetch queue for user action and one for data prefetch.

import { FetchQueue } from "@fetch-queue/core";

const actionQueue = new FetchQueue({maxConnections: 2});
const prefetchQueue = new FetchQueue({maxConnections: 2});

actionQueue.add("https://api.server.com/users/123").then((response) => {
  // Go to profile page for tapped user  
});

prefetchQueue.add("https://api.server.com/notifications").then((response) => {
  // Save notifications to model so user can read it later without waiting
});

Or you can have a separate hostname for prefetch.

const prefetchQueue = new FetchQueue({baseURL: "https://prefetch.server.com"}); // maxConnections is 4 by default

prefetchQueue.add("/notifications").then(/**/);
prefetchQueue.add("/friends").then(/**/);

Install

Note: Polyfill for fetch or promise not included.

npm install --save @fetch-queue/core

About

A http request queue based on fetch() API

Resources

License

Stars

Watchers

Forks

Packages

No packages published