Skip to content

Migrate and Modernize SDK Documentation for Quran Foundation API #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
55bae6e
docs: document support for location-based filters
basit3407 Jun 24, 2025
59f889c
fix: correct response schema for:
basit3407 Jun 24, 2025
cae8f61
fix(docs): correct response schema for
basit3407 Jun 24, 2025
07658bc
fix: correct tafsir typos
basit3407 Jun 24, 2025
b5acdb5
Fix Mushaf typo in content API docs
basit3407 Jun 24, 2025
ef9a858
regenerated api docs after fixing "Mushaf" typos
basit3407 Jun 25, 2025
c973ce2
Merge pull request #12 from basit3407/codex/check-v4.json-for-typos
basit3407 Jun 25, 2025
e957e7e
Merge pull request #13 from basit3407/codex/fix-typo--muhsaf--to--mus…
basit3407 Jun 25, 2025
e938b9c
Replace unrendered model placeholders
basit3407 Jun 25, 2025
048c6ef
Regenerated api docs after fixing model names
basit3407 Jun 25, 2025
6948ec3
Merge pull request #14 from basit3407/codex/count-unrendered-model-pl…
basit3407 Jun 25, 2025
72d1972
Replace placeholder endpoints in v4.json
basit3407 Jun 25, 2025
f00a7af
regenerated api docs after replacing endpoint
basit3407 Jun 25, 2025
f76b799
Merge pull request #15 from basit3407/codex/locate-and-count-endpoint…
basit3407 Jun 25, 2025
0969369
Merge branch 'quran:main' into main
basit3407 Jun 25, 2025
7fef2a6
docs: document mushafId param
basit3407 Jun 26, 2025
4ca124e
Regenerated the docs after the fix
basit3407 Jun 26, 2025
c498c43
Merge pull request #16 from basit3407/codex/update-docs-for-mushafid-…
basit3407 Jun 26, 2025
4dc69d5
Add field reference page and link in API spec
basit3407 Jun 27, 2025
30c9667
Regenerated api docs
basit3407 Jun 27, 2025
3457d65
Fix unicode escapes in field reference
basit3407 Jun 27, 2025
08305e0
Clarify qpc_uthmani_hafs description
basit3407 Jun 27, 2025
2c46663
Merge pull request #17 from basit3407/codex/locate-documentation-for-…
basit3407 Jun 27, 2025
8c804ac
docs: link resource references
basit3407 Jun 27, 2025
f532152
regenerated api docs
basit3407 Jun 27, 2025
2416d29
Merge pull request #18 from basit3407/codex/list-endpoints-referencin…
basit3407 Jun 27, 2025
25f0988
Revert "Merge pull request #16 from basit3407/codex/update-docs-for-m…
basit3407 Jul 1, 2025
e2533d6
Add SDK documentation
basit3407 Jul 3, 2025
049861f
Update SDK docs
basit3407 Jul 3, 2025
66e1279
Merge pull request #19 from basit3407/codex/generate-new-api-document…
basit3407 Jul 3, 2025
70bbc81
Merge branch 'quran:main' into main
basit3407 Jul 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions docs/sdk/authentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
id: authentication
title: "🔑 Authentication"
sidebar_label: Authentication
---

The SDK uses the OAuth2 **Client Credentials** flow behind the scenes. Once you call `configure` with your `clientId` and `clientSecret`, every request automatically obtains and refreshes an access token.

## How it works

1. The SDK requests a token using the [OAuth2 Token Exchange endpoint](https://api-docs.quran.foundation/docs/oauth2_apis_versioned/oauth-2-token-exchange).
2. Tokens are cached until 30 seconds before expiry.
3. All API calls include the `x-auth-token` and `x-client-id` headers for you.

You generally do not need to handle tokens manually. If you wish to override the fetch implementation (for example in React Native), pass a custom `fetchFn` during configuration:

```javascript
import { configure } from '@quranjs/api';
import fetch from 'cross-fetch';

configure({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
fetchFn: fetch,
});
```

For details on the OAuth2 endpoints themselves, see the [Token Exchange documentation](https://api-docs.quran.foundation/docs/oauth2_apis_versioned/oauth-2-token-exchange).
17 changes: 17 additions & 0 deletions docs/sdk/endpoints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
id: endpoints
title: "🗂️ Endpoint Reference"
sidebar_label: Endpoint Reference
---

Below is an overview of the main API groups exposed via the SDK. Each link points to the full API documentation on api-docs.quran.foundation.

- **Chapters** – [List Chapters](https://api-docs.quran.foundation/docs/content_apis_versioned/list-chapters), [Get Chapter](https://api-docs.quran.foundation/docs/content_apis_versioned/get-chapter), [Chapter Info](https://api-docs.quran.foundation/docs/content_apis_versioned/info)
- **Verses** – [Verses by Chapter](https://api-docs.quran.foundation/docs/content_apis_versioned/verses-by-chapter-number), [Verses by Key](https://api-docs.quran.foundation/docs/content_apis_versioned/verses-by-verse-key), [Random Verse](https://api-docs.quran.foundation/docs/content_apis_versioned/random-verse) and others
- **Juzs** – [List Juzs](https://api-docs.quran.foundation/docs/content_apis_versioned/juzs)
- **Audio** – [Chapter Recitation Files](https://api-docs.quran.foundation/docs/content_apis_versioned/chapter-reciter-audio-files), [Verse Recitations](https://api-docs.quran.foundation/docs/content_apis_versioned/list-surah-recitation)
- **Resources** – [Translations](https://api-docs.quran.foundation/docs/content_apis_versioned/translations), [Tafsirs](https://api-docs.quran.foundation/docs/content_apis_versioned/tafsirs), [Languages](https://api-docs.quran.foundation/docs/content_apis_versioned/languages) and more
- **Search** – [Search Endpoint](https://api-docs.quran.foundation/docs/content_apis_versioned/search)
- **OAuth2** – [Token Endpoint](https://api-docs.quran.foundation/docs/oauth2_apis_versioned/token)

For advanced query parameters and response schemas, consult the linked documentation.
49 changes: 49 additions & 0 deletions docs/sdk/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
id: index
title: "📦 SDK Overview"
sidebar_label: SDK Overview
---

The Quran Foundation JavaScript SDK simplifies interaction with the [Quran Foundation API](https://api-docs.quran.foundation). It works in Node.js and modern browsers and handles authentication for you.

## Installation

```bash
npm install @quranjs/api
```

or with Yarn:

```bash
yarn add @quranjs/api
```

or with pnpm:

```bash
pnpm add @quranjs/api
```

## Basic Setup

Before using the SDK, configure it with your client credentials. You can obtain a **Client ID** and **Client Secret** from the [Request Access](https://api-docs.quran.foundation/request-access) page:

```javascript
import { configure, quran } from '@quranjs/api';

configure({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
});
```

After configuration you can call the SDK methods directly. Tokens are fetched and refreshed automatically.

### Example: list chapters

```javascript
const chapters = await quran.qf.chapters.findAll();
console.log(chapters);
```

Continue to the [Authentication](authentication.md) guide for details on how tokens are managed.
14 changes: 14 additions & 0 deletions docs/sdk/migration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
id: migration
title: "🛠️ Migrating from QuranJS API"
sidebar_label: Migration Guide
---

If you previously used the `@quranjs/api` SDK against the Quran.com endpoints, switching to the new Quran Foundation API requires a few changes.

1. **Base URLs** – The new SDK defaults to `https://apis.quran.foundation` and `https://oauth2.quran.foundation`. Remove any overrides pointing to quran.com.
Copy link
Preview

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The migration guide should provide specific examples of how to update existing code rather than just describing what needs to change. Consider adding before/after code examples for common migration scenarios.

Suggested change
1. **Base URLs** – The new SDK defaults to `https://apis.quran.foundation` and `https://oauth2.quran.foundation`. Remove any overrides pointing to quran.com.
1. **Base URLs** – The new SDK defaults to `https://apis.quran.foundation` and `https://oauth2.quran.foundation`. Remove any overrides pointing to quran.com.
**Before:**
```javascript
const api = require('@quranjs/api');
api.configure({
baseUrl: 'https://api.quran.com',
});

After:

const api = require('@quran.foundation/api');
api.configure({
    baseUrl: 'https://apis.quran.foundation',
});

Copilot uses AI. Check for mistakes.

2. **Authentication** – OAuth2 is now mandatory. Calls without a valid token will fail. Make sure to call `configure` with both `clientId` and `clientSecret`.
3. **API Differences** – Several endpoint paths have changed and some fields were renamed. Consult the [Endpoint Reference](endpoints.md) and the official API docs for the exact routes.
4. **Utility Functions** – Validation helpers now live under `quran.utils` and return boolean values.

Most method names remain the same, so in many cases updating the configuration and endpoint URLs is all that is needed.
82 changes: 82 additions & 0 deletions docs/sdk/usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
---
id: usage
title: "📚 SDK Usage"
sidebar_label: Usage Examples
---

This page highlights the main wrappers exported by the SDK. All examples assume you have already called `configure`.

## Chapters

```javascript
// List all chapters
const chapters = await quran.qf.chapters.findAll();

// Get a single chapter by ID
const chapter = await quran.qf.chapters.findById('1');

// Retrieve chapter information
const info = await quran.qf.chapters.findInfoById('1');
```

## Verses

```javascript
// Get verses of a chapter
const verses = await quran.qf.verses.findByChapter('1');

// Fetch a verse by key
const verse = await quran.qf.verses.findByKey('1:1');

// Retrieve a random verse
const random = await quran.qf.verses.findRandom();
```

Additional helpers include `findByPage`, `findByJuz`, `findByHizb` and `findByRub`.
Copy link
Preview

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing comma before 'and' in the list. Should be: 'Additional helpers include findByPage, findByJuz, findByHizb, and findByRub.'

Suggested change
Additional helpers include `findByPage`, `findByJuz`, `findByHizb` and `findByRub`.
Additional helpers include `findByPage`, `findByJuz`, `findByHizb`, and `findByRub`.

Copilot uses AI. Check for mistakes.


## Juzs

```javascript
const juzs = await quran.qf.juzs.findAll();
```

## Audio

```javascript
// All chapter recitations for a reciter
const files = await quran.qf.audio.findAllChapterRecitations('2');

// Verse recitations by chapter
const recitations = await quran.qf.audio.findVerseRecitationsByChapter('1', '2');
```

Other helpers cover pages, hizbs, rubs and specific verses.

## Resources

```javascript
// Available translations
const translations = await quran.qf.resources.findAllTranslations();

// Reciter information
const reciterInfo = await quran.qf.resources.findRecitationInfo('1');
```

This wrapper also exposes methods for languages, tafsirs, recitation styles, chapter reciters and more.

## Search

```javascript
const results = await quran.qf.search.search('mercy');
```

## Utilities

```javascript
import { quran } from '@quranjs/api';

quran.utils.isValidVerseKey('2:255'); // true
quran.utils.isValidChapterId('115'); // false
```

See the [Endpoint Reference](endpoints.md) for a list of API routes these wrappers use.
6 changes: 6 additions & 0 deletions docusaurus.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ const config = {
position: "left",
label: "🚀 Quick Start",
},
{
type: "doc",
docId: "sdk/index",
position: "left",
label: "SDK",
},
{
type: "doc",
docId: "updates/index",
Expand Down
11 changes: 11 additions & 0 deletions sidebars.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ const sidebars = {
id: "quickstart/index", // ✅ Add here too if needed in sidebar
label: "🚀 Quick Start Guide",
},
{
type: "category",
label: "SDK",
link: { type: "doc", id: "sdk/index" },
items: [
"sdk/authentication",
"sdk/usage",
"sdk/endpoints",
"sdk/migration",
],
},

// {
// type: "html",
Expand Down