Skip to content

saikothasan/quran-api

Repository files navigation

Al-Quran API

Al-Quran API License Version

A comprehensive RESTful API for accessing the Holy Quran with translations in multiple languages including Arabic, English, Bengali, and more.

🌐 Live Demo

Visit the live API and documentation at https://alquran-api.pages.dev

✨ Features

  • Multilingual Support: Access the Quran in multiple languages including Arabic, English, Bengali, and more
  • Complete Quran Data: All 114 surahs with their verses, translations, and metadata
  • RESTful API: Simple and intuitive API endpoints
  • Search Functionality: Search for specific words or phrases across the entire Quran
  • No Authentication Required: Open access for all users
  • CORS Enabled: Can be used in web applications
  • Edge Runtime: Fast response times with Vercel Edge Runtime

πŸ“š API Documentation

Base URL

https://alquran-api.pages.dev/api/quran

Endpoints

Endpoint Description Parameters
/api/quran Get all surahs lang (optional)
/api/quran/surah/{id} Get a specific surah id (required), lang (optional)
/api/quran/surah/{id}/verse/{verseId} Get a specific verse id (required), verseId (required), lang (optional)
/api/quran/search Search the Quran q (required), lang (optional)
/api/quran/languages Get available languages None

Language Parameter

All endpoints accept a lang query parameter to specify the language. If not specified, English (en) is used as the default language.

Available language codes:

  • ar - Arabic
  • bn - Bengali
  • en - English
  • es - Spanish
  • fr - French
  • id - Indonesian
  • ru - Russian
  • sv - Swedish
  • tr - Turkish
  • ur - Urdu
  • zh - Chinese
  • transliteration - Transliteration

Example Requests

Get all surahs in English

GET https://alquran-api.pages.dev/api/quran?lang=en

Get Surah Al-Fatihah in Arabic

GET https://alquran-api.pages.dev/api/quran/surah/1?lang=ar

Get a specific verse

GET https://alquran-api.pages.dev/api/quran/surah/1/verse/1?lang=en

Search for "mercy" in the Quran

GET https://alquran-api.pages.dev/api/quran/search?q=mercy&lang=en

Get available languages

GET https://alquran-api.pages.dev/api/quran/languages

πŸš€ Getting Started

Prerequisites

Installation

  1. Clone the repository:
    git clone https://github.com/saikothasan/quran-api.git
    cd quran-api

2. Install dependencies:

```shellscript
npm install
# or
yarn
  1. Run the development server:
npm run dev
# or
yarn dev
  1. Open http://localhost:3000 in your browser to see the result.

Project Structure

quran-api/
β”œβ”€β”€ app/                  # Next.js App Router
β”‚   β”œβ”€β”€ api/              # API routes
β”‚   β”‚   └── quran/        # Quran API endpoints
β”‚   β”œβ”€β”€ about/            # About page
β”‚   β”œβ”€β”€ demo/             # Demo application
β”‚   β”œβ”€β”€ documentation/    # API documentation
β”‚   β”œβ”€β”€ search/           # Search page
β”‚   β”œβ”€β”€ layout.tsx        # Root layout
β”‚   └── page.tsx          # Home page
β”œβ”€β”€ components/           # React components
β”‚   β”œβ”€β”€ ui/               # UI components (shadcn/ui)
β”‚   └── ...               # Other components
β”œβ”€β”€ lib/                  # Utility functions
β”‚   └── quran-utils.ts    # Quran-related utilities
β”œβ”€β”€ public/               # Static files
β”‚   β”œβ”€β”€ quran.json        # Arabic Quran data
β”‚   β”œβ”€β”€ quran_en.json     # English translation
β”‚   β”œβ”€β”€ quran_bn.json     # Bengali translation
β”‚   └── ...               # Other language files
└── ...                   # Configuration files

πŸ“¦ Deployment

This project is deployed on Vercel and is available at https://alquran-api.pages.dev.

To deploy your own instance:

  1. Fork this repository
  2. Create a new project on Vercel
  3. Connect your forked repository
  4. Deploy

🧩 Using the API in Your Projects

JavaScript (Fetch)

// Get all surahs in English
fetch('https://alquran-api.pages.dev/api/quran?lang=en')
  .then(response => response.json())
  .then(data => {
    console.log(data);
  })
  .catch(error => {
    console.error('Error:', error);
  });

React Example

import { useState, useEffect } from 'react';

function QuranViewer() {
  const [surah, setSurah] = useState(null);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    async function fetchSurah() {
      try {
        setLoading(true);
        const response = await fetch(
          'https://alquran-api.pages.dev/api/quran/surah/1?lang=en'
        );
        
        if (!response.ok) {
          throw new Error('Failed to fetch');
        }
        
        const data = await response.json();
        setSurah(data);
      } catch (err) {
        setError(err.message);
      } finally {
        setLoading(false);
      }
    }

    fetchSurah();
  }, []);

  if (loading) return <div>Loading...</div>;
  if (error) return <div>Error: {error}</div>;
  if (!surah) return <div>No data found</div>;

  return (
    <div>
      <h1>{surah.transliteration} ({surah.translation})</h1>
      <div>
        {surah.verses.map(verse => (
          <div key={verse.id}>
            <p>{verse.text}</p>
            <p>{verse.translation}</p>
          </div>
        ))}
      </div>
    </div>
  );
}

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“§ Contact

Saiko Thasan - @saikothasan

Project Link: https://github.com/saikothasan/quran-api

πŸ™ Acknowledgements

About

Al-Quran API - Multilingual Quran API with Translations

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages