SDK to access alathar.net content.
To install zubair-ali-zai-sdk, use npm or yarn:
npm install zubair-ali-zai-sdk
# or
yarn add zubair-ali-zai-sdk
# or
pnpm i zubair-ali-zai-sdk
import { init } from 'zubair-ali-zai-sdk';
There are two ways to initialize the SDK to process the requests. Either set the environment variable directly:
ZUBAIR_ALI_ZAI_API="https://domain.com/:book/:id"
or use the init
function:
import { init } from 'zubair-ali-zai-sdk';
init('https://domain.com/:book/:id');
Note that your URL pattern for the endpoint must have the :book
and :id
placeholders in it so that the correct book ID and hadith number can be substituted.
Retrieve metadata about a specific hadith.
(async () => {
try {
let hadith = await getAbuDawud(123); // from Sunan Abu Dawud
hadith = await getIbnMajah(123); // from Sunan Ibn Majah
hadith = await getMishkaat(123); //
hadith = await getNasai(123);
hadith = await getTirmidhi(123);
console.log(hadith); // { arabic: 'حَدَّثَنَا مَحْمُودُ بْنُ خَالِدٍ', description: 'إسنادہ ضعیف باب ما جاء فی الرجل', hukm: 'حسن' }
} catch (error) {
console.error(error.message);
}
})();