Axios introduction
Hyper Fetch axios
adapter is a simple integration that allows Hyper Fetch users to utilize a lot of features
of the axios
library along with all the features available in Hyper Fetch.
Getting Started
In order to set axios
adapter, you have to import it from the @hyper-fetch/axios
package:
import { Client } from "@hyper-fetch/core";
import { axiosAdapter } from "@hyper-fetch/axios";
const client = new Client({ url: "base-url" }).setAdapter(axiosAdapter);
...and voila! It's done. Now you can set all the axios options, either during the request initialization or via
setOptions
method:
const client = new Client({ url: "base-url" }).setAdapter(axiosAdapter);
const request = client.createRequest()({
endpoint: "/shared-endpoint",
options: {} // here
});
const requestWithOptions = request.setOptions({}) // or here
Differences
- You should not pass the
baseUrl
,method
, andurl
in the axios options. They will be overwritten by the Hyper Fetch adapter.