Skip to content

Commit 66e1279

Browse files
authored
Merge pull request #19 from basit3407/codex/generate-new-api-documentation-for-docusaurus
Add JavaScript SDK docs
2 parents 25f0988 + 049861f commit 66e1279

7 files changed

Lines changed: 207 additions & 0 deletions

File tree

‎docs/sdk/authentication.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
id: authentication
3+
title: "🔑 Authentication"
4+
sidebar_label: Authentication
5+
---
6+
7+
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.
8+
9+
## How it works
10+
11+
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).
12+
2. Tokens are cached until 30 seconds before expiry.
13+
3. All API calls include the `x-auth-token` and `x-client-id` headers for you.
14+
15+
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:
16+
17+
```javascript
18+
import { configure } from '@quranjs/api';
19+
import fetch from 'cross-fetch';
20+
21+
configure({
22+
clientId: 'YOUR_CLIENT_ID',
23+
clientSecret: 'YOUR_CLIENT_SECRET',
24+
fetchFn: fetch,
25+
});
26+
```
27+
28+
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).

‎docs/sdk/endpoints.md‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
id: endpoints
3+
title: "🗂️ Endpoint Reference"
4+
sidebar_label: Endpoint Reference
5+
---
6+
7+
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.
8+
9+
- **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)
10+
- **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
11+
- **Juzs**[List Juzs](https://api-docs.quran.foundation/docs/content_apis_versioned/juzs)
12+
- **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)
13+
- **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
14+
- **Search**[Search Endpoint](https://api-docs.quran.foundation/docs/content_apis_versioned/search)
15+
- **OAuth2**[Token Endpoint](https://api-docs.quran.foundation/docs/oauth2_apis_versioned/token)
16+
17+
For advanced query parameters and response schemas, consult the linked documentation.

‎docs/sdk/index.md‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
id: index
3+
title: "📦 SDK Overview"
4+
sidebar_label: SDK Overview
5+
---
6+
7+
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.
8+
9+
## Installation
10+
11+
```bash
12+
npm install @quranjs/api
13+
```
14+
15+
or with Yarn:
16+
17+
```bash
18+
yarn add @quranjs/api
19+
```
20+
21+
or with pnpm:
22+
23+
```bash
24+
pnpm add @quranjs/api
25+
```
26+
27+
## Basic Setup
28+
29+
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:
30+
31+
```javascript
32+
import { configure, quran } from '@quranjs/api';
33+
34+
configure({
35+
clientId: 'YOUR_CLIENT_ID',
36+
clientSecret: 'YOUR_CLIENT_SECRET',
37+
});
38+
```
39+
40+
After configuration you can call the SDK methods directly. Tokens are fetched and refreshed automatically.
41+
42+
### Example: list chapters
43+
44+
```javascript
45+
const chapters = await quran.qf.chapters.findAll();
46+
console.log(chapters);
47+
```
48+
49+
Continue to the [Authentication](authentication.md) guide for details on how tokens are managed.

‎docs/sdk/migration.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
id: migration
3+
title: "🛠️ Migrating from QuranJS API"
4+
sidebar_label: Migration Guide
5+
---
6+
7+
If you previously used the `@quranjs/api` SDK against the Quran.com endpoints, switching to the new Quran Foundation API requires a few changes.
8+
9+
1. **Base URLs** – The new SDK defaults to `https://apis.quran.foundation` and `https://oauth2.quran.foundation`. Remove any overrides pointing to quran.com.
10+
2. **Authentication** – OAuth2 is now mandatory. Calls without a valid token will fail. Make sure to call `configure` with both `clientId` and `clientSecret`.
11+
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.
12+
4. **Utility Functions** – Validation helpers now live under `quran.utils` and return boolean values.
13+
14+
Most method names remain the same, so in many cases updating the configuration and endpoint URLs is all that is needed.

‎docs/sdk/usage.md‎

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
id: usage
3+
title: "📚 SDK Usage"
4+
sidebar_label: Usage Examples
5+
---
6+
7+
This page highlights the main wrappers exported by the SDK. All examples assume you have already called `configure`.
8+
9+
## Chapters
10+
11+
```javascript
12+
// List all chapters
13+
const chapters = await quran.qf.chapters.findAll();
14+
15+
// Get a single chapter by ID
16+
const chapter = await quran.qf.chapters.findById('1');
17+
18+
// Retrieve chapter information
19+
const info = await quran.qf.chapters.findInfoById('1');
20+
```
21+
22+
## Verses
23+
24+
```javascript
25+
// Get verses of a chapter
26+
const verses = await quran.qf.verses.findByChapter('1');
27+
28+
// Fetch a verse by key
29+
const verse = await quran.qf.verses.findByKey('1:1');
30+
31+
// Retrieve a random verse
32+
const random = await quran.qf.verses.findRandom();
33+
```
34+
35+
Additional helpers include `findByPage`, `findByJuz`, `findByHizb` and `findByRub`.
36+
37+
## Juzs
38+
39+
```javascript
40+
const juzs = await quran.qf.juzs.findAll();
41+
```
42+
43+
## Audio
44+
45+
```javascript
46+
// All chapter recitations for a reciter
47+
const files = await quran.qf.audio.findAllChapterRecitations('2');
48+
49+
// Verse recitations by chapter
50+
const recitations = await quran.qf.audio.findVerseRecitationsByChapter('1', '2');
51+
```
52+
53+
Other helpers cover pages, hizbs, rubs and specific verses.
54+
55+
## Resources
56+
57+
```javascript
58+
// Available translations
59+
const translations = await quran.qf.resources.findAllTranslations();
60+
61+
// Reciter information
62+
const reciterInfo = await quran.qf.resources.findRecitationInfo('1');
63+
```
64+
65+
This wrapper also exposes methods for languages, tafsirs, recitation styles, chapter reciters and more.
66+
67+
## Search
68+
69+
```javascript
70+
const results = await quran.qf.search.search('mercy');
71+
```
72+
73+
## Utilities
74+
75+
```javascript
76+
import { quran } from '@quranjs/api';
77+
78+
quran.utils.isValidVerseKey('2:255'); // true
79+
quran.utils.isValidChapterId('115'); // false
80+
```
81+
82+
See the [Endpoint Reference](endpoints.md) for a list of API routes these wrappers use.

‎docusaurus.config.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,12 @@ const config = {
153153
position: "left",
154154
label: "🚀 Quick Start",
155155
},
156+
{
157+
type: "doc",
158+
docId: "sdk/index",
159+
position: "left",
160+
label: "SDK",
161+
},
156162
{
157163
type: "doc",
158164
docId: "updates/index",

‎sidebars.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ const sidebars = {
5757
id: "quickstart/index", // ✅ Add here too if needed in sidebar
5858
label: "🚀 Quick Start Guide",
5959
},
60+
{
61+
type: "category",
62+
label: "SDK",
63+
link: { type: "doc", id: "sdk/index" },
64+
items: [
65+
"sdk/authentication",
66+
"sdk/usage",
67+
"sdk/endpoints",
68+
"sdk/migration",
69+
],
70+
},
6071

6172
// {
6273
// type: "html",

0 commit comments

Comments
 (0)