:warning: This library is experimental and subject to change. Will be stable when v0.0.1 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();

Top categories

svelte logo

Need a Svelte website built?

Hire a professional Svelte developer today.
Loading Svelte Themes