Fetch Plus

🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Alternatives To Fetch Plus
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Ky9,84687526020 days ago53September 03, 202248mitTypeScript
🌳 Tiny & elegant JavaScript HTTP client based on the browser Fetch API
Wretch3,941485613 days ago52September 27, 20223mitTypeScript
A tiny wrapper built around fetch with an intuitive syntax. :candy:
Vue Json Excel6175228a year ago43October 05, 202066mitVue
Fakerest399141293 months ago25March 29, 20215mitJavaScript
Patch fetch/XMLHttpRequest to fake a REST API server in the browser, based on JSON data.
Ffq378
8 months ago9May 05, 2022mitPython
A tool to find sequencing data and metadata from public databases.
Dms152
a year ago22mitJavaScript
基于Json Schema的动态Json数据配置平台
Vanilla Js144
a month ago1JavaScript
Projects using pure JavaScript without any external libraries or frameworks
Fetch Polyfill1401426 years ago3November 01, 20163JavaScript
fetch polyfill which supports all mainstream browsers, even IE6, IE7, IE8.....
Fetch Plus11633143 years ago20November 21, 201630otherJavaScript
🐕 Fetch+ is a convenient Fetch API replacement with first-class middleware support.
Hades93
4 years ago1mitGo
Hades is a hypermedia-based HTTP/2 reverse proxy for JSON:API servers.
Alternatives To Fetch Plus
Select To Compare


Alternative Project Comparisons
Readme

Fetch+

A convenient Fetch API library with first-class middleware support.

version license Package Quality installs

Features

  • Drop-in replacement for fetch().
  • Simple BREAD methods for consuming REST APIs.
  • A "queries" object option for building safe query strings more easily.
  • All options can be computed values: myHeaders: () => values
  • Custom middlewares to manipute requests, responses, and caught errors.
  • Useful middlewares and handlers (JSON/Auth/CSRF/Immutable etc) available as separate npm packages.
  • Fetch API Streams draft handler with an Observable interface.
  • Runs in Node and all browsers.

Installation

npm install --save fetch-plus  isomorphic-fetch

Additional middlewares

npm install --save fetch-plus-basicauth
npm install --save fetch-plus-bearerauth
npm install --save fetch-plus-csrf
npm install --save fetch-plus-immutable
npm install --save fetch-plus-json
npm install --save fetch-plus-oauth
npm install --save fetch-plus-stream
npm install --save fetch-plus-useragent
npm install --save fetch-plus-xml

Usage

import/require

import {fetch, createClient} from "fetch-plus";

fetch

fetch("http://some.api.example/v1", {
	query: {foo: "bar"},                // Query string object. So convenient.
	body: () => "R2-D2"                 // Computed values are computed.
});

createClient

Creates a RESTful client so middlewares can be added to it.

const client = createClient("http://some.api.example/v1");

client.addMiddleware

Create middlewares like: (request) => (response) => response

client.addMiddleware(
	(request) => {
		request.path += ".json";
		request.options.headers["Content-Type"] = "application/json; charset=utf-8";

		return (response) => response.json();
	}
);

client.request

request performs generic requests to the configured endpoint.

client.request("posts/25/comments", {
	method: "POST",
	body: {comment: "C-3PO"}
});

client.browse|read|edit|add|destroy|replace

BREAD helpers that perform requests to the configured endpoint.

client.browse(            
	"posts"                    // A string...
);

client.add(
	["posts", 1, "comments"],  // ...or an array like ["posts", id, "comments"]
	{body: "C-3PO"}            // Regular Fetch API body option.
);

client.list|create|read|update|destroy

CRUD aliases that perform requests to the configured endpoint.

client.list(            
	"posts"                    // A string...
);

client.create(
	["posts", 1, "comments"],  // ...or an array like ["posts", id, "comments"]
	{body: "C-3PO"}            // Regular Fetch API body option.
);

handlers

Handlers take configuration and return functions to pass to .then().

// Transform JSON with fetch-plus-json.
import plusJson from "fetch-plus-json";

fetch("http://some.api.example/v1/posts").then(plusJson.handler({some:"config"}));

See example for more.

Community

Let's start one together! After you ★Star this project, follow me @Rygu on Twitter.

License

BSD 3-Clause license. Copyright © 2015, Rick Wong. All rights reserved.

Popular Fetch Projects
Popular Json Projects
Popular Networking Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Javascript
Json
Http
Rest
Xml
Promise
Fetch
Ajax
Isomorphic
User Agent
Csrf
Immutablejs