Hadith API Documentation

Getting Started
Base URL:
BASE_URL
https://hadith-api.onrender.com

Authentication

All API requests require the appropriate headers:

const axios = require('axios');

const config = {
  method: 'GET',
  url: 'https://hadith-api.onrender.com/api/v1/hadith/en-sahihbukhari/1',
  headers: { 
    'Content-Type': 'application/json',
    'x-api-key': 'YOUR_API_KEY'
  }
};

axios(config)
  .then(response => console.log(JSON.stringify(response.data)))
  .catch(error => console.log(error));

Example Request

"text-[#569CD6]">const axios = "text-[#569CD6]">require('axios');
 
"text-[#569CD6]">const config = {
  method: 'get',
  url: 'https://hadith-api.onrender.com/api/v1/hadith/eng-bukhari/1',
  headers: { 
    'Content-Type': 'application/json'
  }
};
 
axios(config)
  ."text-[#DCDCAA]">then(response => "text-[#4EC9B0]">console."text-[#DCDCAA]">log(JSON."text-[#DCDCAA]">stringify(response.data)))
  ."text-[#DCDCAA]">catch(error => "text-[#4EC9B0]">console."text-[#DCDCAA]">log(error));
1. Get Hadith by Number
GET /api/v1/hadith/:edition/:number

Headers: Content-Type: application/json

Example Request: GET /api/v1/hadith/eng-bukhari/1

Sample Response:
{
  "id": 1,
  "text": "Hadith text here",
  "edition": "eng-bukhari"
}
2. Get All Editions
GET /api/v1/hadith/editions

Headers: Content-Type: application/json

Example Request: GET /api/v1/hadith/editions

Sample Response:
[
  {
    "language": "eng",
    "name": "bukhari",
    "id": "eng-bukhari"
  },
  {
    "language": "ara",
    "name": "muslim",
    "id": "ara-muslim"
  }
]
3. Get Sections
GET /api/v1/hadith/:edition/sections/:number

Headers: Content-Type: application/json

Example Request: GET /api/v1/hadith/eng-bukhari/sections/1

Sample Response:
{
  "section": 1,
  "title": "Section Title",
  "hadiths": [
    {
      "id": 1,
      "text": "Hadith text here"
    },
    {
      "id": 2,
      "text": "Another Hadith text here"
    }
  ]
}
4. Get Hadith API Info
GET /api/v1/hadith/info

Headers: Content-Type: application/json

Example Request: GET /api/v1/hadith/info

Sample Response:
{
  "version": "1.0",
  "description": "Hadith API Information",
  "source": "https://cdn.jsdelivr.net/gh/fawazahmed0/hadith-api"
}
5. Get Random Hadith
GET /api/v1/hadith/random

Headers: Content-Type: application/json

Query Parameters: ?bookName={bookName}

Example Request: GET /api/v1/hadith/random?bookName=bukhari

Sample Response:
{
  "id": 1,
  "text": "Random Hadith text here",
  "book": "bukhari"
}
Available Book Names:
bukhari
abudawud
tirmidhi
muslim
ibnmajah
Note: Use one of the book names in the query parameter to fetch a random Hadith from that book.