npm.io
0.0.1-alpha.2 • Published 5 years ago

octofetch

Licence
MIT
Version
0.0.1-alpha.2
Deps
0
Size
103 kB
Vulns
0
Weekly
0

This library is experimental and subject to change. Will be stable when v0.1.0 is released.

OctoFetch Logo

OctoFetch

Javascript/Typescript library for fetching data from APIs with zero dependencies.

CI badge CI badge CI badge
NPM Downloads NPM Version Bundle Size

Documentation

You can find the full documentation here: Documentation

How does it work

OctoFetch is a thin layer on top of the browser native Fetch API, which is supported in all modern browsers and polyfilled by most tools such as Nuxt.js, Next.js, create-react-app, vue-cli, etc. It allows for much less boilerplate and more reusable code.

OctoFetch is made for browser, but can be used in Node.JS using the package isomorphic-fetch for polyfilling the native Fetch API.

Install the package

Using NPM:
npm install octofetch --save
Using YARN
yarn add octofetch

Simple usage

Javascript
import octofetch from "octofetch";

octofetch()
    .get("https://localhost:5000/api/users/:id")
    .path("id", userId)
    .header("Token", "Bearer my-token-here")
    .fetch()
    .then((user) => console.log(`Got user: ${user}`))
    .catch((error) => console.log(error.code));
Typescript
import octofetch from "octofetch";

const users = await octofetch<User[]>().get("https://localhost:5000/api/users").fetch();