• Techniques

Custom fetcher

By default, all functions that interact with the Quran.com API use the global fetch function.

You can override this by passing a custom fetcher (as fetchFn) to the options object of any method.

💡

Note that the fetchFn accepts a string url and must return a promise with the JSON response.

Examples

Axios

import axios from 'axios';
 
const chapters = await quran.v4.chapters.findAll({
  fetchFn: (url) => axios.get(url).then((res) => res.data),
});

Node-fetch

import fetch from 'node-fetch';
 
const chapters = await quran.v4.chapters.findAll({
  fetchFn: async (url) => {
    const response = await fetch(url);
    return response.json();
  },
});
Last updated on April 9, 2023