JavaScript/TypeScript library for fetching data from APIs with zero dependencies.
You can find the full documentation here: Documentation
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.
npm install octofetch --save
yarn add octofetch
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));
import octofetch from "octofetch";
const users = await octofetch<User[]>().get("https://localhost:5000/api/users").fetch();