Skip to content

Commit

Permalink
Update README with new disableRequest option
Browse files Browse the repository at this point in the history
  • Loading branch information
cuibonobo committed Dec 23, 2023
1 parent b006311 commit 0e34684
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ npm install @haverstack/axios-fetch-adapter
```

## Use
The default use-case for this library is:
```javascript
import axios from "axios";
import fetchAdapter from "@haverstack/axios-fetch-adapter";
Expand All @@ -23,7 +24,8 @@ const client = axios.create({
});
```

To use with a custom `fetch` function:
### Using with custom `fetch` functions
If your application does not use a globally-available `fetch`, you can specify your own custom `fetch` function instead:
```javascript
import axios from "axios";
import { createFetchAdapter } from "@haverstack/axios-fetch-adapter";
Expand All @@ -35,7 +37,25 @@ const client = axios.create({
});
```

To use with the Square API:
If your application allows for using non-fully-qualified URLs, e.g. `/foo`, use the `disableRequest` option to pass URLs directly to your custom `fetch` function without creating a `Request` object:
```javascript
import axios from "axios";
import { createFetchAdapter } from "@haverstack/axios-fetch-adapter";
import myCustomFetch from "my-custom-fetch";

const customAdapter = createFetchAdapter({
fetch: myCustomFetch,
disableRequest: true
});
const client = axios.create({
adapter: myCustomFetchAdapter
});
```

**Note:** A side effect of the `disableRequest` option is that the `AxiosResponse` object will only have the request URL in its `request` property instead of a `Request` object. This means that accessing, for example, `response.request.url` will throw an error.

### Using with the Square Node.js SDK
To use this library with the [`square`](https://www.npmjs.com/package/square) package to manage your [Square](https://squareup.com/) resources:
```javascript
import { Client, Environment } from "square";
import fetchAdapter from "@haverstack/axios-fetch-adapter";
Expand Down

0 comments on commit 0e34684

Please sign in to comment.