-
Notifications
You must be signed in to change notification settings - Fork 8
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
basit3407
wants to merge
31
commits into
quran:main
Choose a base branch
from
basit3407:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
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 59f889c
fix: correct response schema for:
basit3407 cae8f61
fix(docs): correct response schema for
basit3407 07658bc
fix: correct tafsir typos
basit3407 b5acdb5
Fix Mushaf typo in content API docs
basit3407 ef9a858
regenerated api docs after fixing "Mushaf" typos
basit3407 c973ce2
Merge pull request #12 from basit3407/codex/check-v4.json-for-typos
basit3407 e957e7e
Merge pull request #13 from basit3407/codex/fix-typo--muhsaf--to--mus…
basit3407 e938b9c
Replace unrendered model placeholders
basit3407 048c6ef
Regenerated api docs after fixing model names
basit3407 6948ec3
Merge pull request #14 from basit3407/codex/count-unrendered-model-pl…
basit3407 72d1972
Replace placeholder endpoints in v4.json
basit3407 f00a7af
regenerated api docs after replacing endpoint
basit3407 f76b799
Merge pull request #15 from basit3407/codex/locate-and-count-endpoint…
basit3407 0969369
Merge branch 'quran:main' into main
basit3407 7fef2a6
docs: document mushafId param
basit3407 4ca124e
Regenerated the docs after the fix
basit3407 c498c43
Merge pull request #16 from basit3407/codex/update-docs-for-mushafid-…
basit3407 4dc69d5
Add field reference page and link in API spec
basit3407 30c9667
Regenerated api docs
basit3407 3457d65
Fix unicode escapes in field reference
basit3407 08305e0
Clarify qpc_uthmani_hafs description
basit3407 2c46663
Merge pull request #17 from basit3407/codex/locate-documentation-for-…
basit3407 8c804ac
docs: link resource references
basit3407 f532152
regenerated api docs
basit3407 2416d29
Merge pull request #18 from basit3407/codex/list-endpoints-referencin…
basit3407 25f0988
Revert "Merge pull request #16 from basit3407/codex/update-docs-for-m…
basit3407 e2533d6
Add SDK documentation
basit3407 049861f
Update SDK docs
basit3407 66e1279
Merge pull request #19 from basit3407/codex/generate-new-api-document…
basit3407 70bbc81
Merge branch 'quran:main' into main
basit3407 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Suggested change
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
|
||||||
## 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
After:
Copilot uses AI. Check for mistakes.