Skip to content

Commit 0b8c657

Browse files
committed
docs: document fetchFn
1 parent 4ec0c67 commit 0b8c657

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

docs/src/pages/_meta.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"index": "Introduction",
3+
"techniques": "Techniques",
34
"chapters": "Chapters",
45
"verses": "Verses",
56
"search": "Search",
67
"juzs": "Juzs",
78
"audio": "Audio",
89
"resources": "Resources",
910
"utils": "Utilities"
10-
}
11+
}

docs/src/pages/techniques.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
## Custom fetcher
2+
3+
By default, all functions that interact with the [Quran.com API](https://quran.api-docs.io/v4) use the global `fetch` function.
4+
5+
You can override this by passing a custom fetcher (as `fetchFn`) to the options object of any method.
6+
7+
import { Callout } from 'nextra-theme-docs';
8+
9+
<Callout>
10+
Note that the `fetchFn` accepts a string url and must return a promise with
11+
the JSON response.
12+
</Callout>
13+
14+
### Examples
15+
16+
#### Axios
17+
18+
```ts
19+
import axios from 'axios';
20+
21+
const chapters = await quran.v4.chapters.findAll({
22+
fetchFn: (url) => axios.get(url).then((res) => res.data),
23+
});
24+
```
25+
26+
---
27+
28+
#### Node-fetch
29+
30+
```ts
31+
import fetch from 'node-fetch';
32+
33+
const chapters = await quran.v4.chapters.findAll({
34+
fetchFn: async (url) => {
35+
const response = await fetch(url);
36+
return response.json();
37+
},
38+
});
39+
```

0 commit comments

Comments
 (0)