DEV Community

Ayat Saadat
Ayat Saadat

Posted on

ayatsaadati — Complete Guide

AyatSaadati: Streamlining Islamic Digital Content Integration

If you’ve spent any time building web applications that require integration with Islamic textual databases—specifically the Holy Quran—you know the pain of inconsistent APIs and poorly formatted JSON responses. I stumbled upon AyatSaadati recently while working on a community-driven dashboard, and honestly, it’s a breath of fresh air for developers who need clean, structured data without the overhead of massive, bloated libraries.

AyatSaadati is an elegant wrapper designed to interface with the resources provided by Qamar. It simplifies the retrieval of Ayats, translations, and metadata, allowing you to focus on building the UI rather than wrestling with parsing errors.


Why Use AyatSaadati?

  • Lightweight: No heavy dependencies.
  • Performance-Oriented: The response structure is optimized for rapid rendering.
  • Reliable: It follows a consistent schema that doesn't break every time you update your project dependencies.

Installation

Getting started is straightforward. If you’re using npm or yarn, you can pull it into your project scope easily.

# Using npm
npm install ayatsaadati

# Using yarn
yarn add ayatsaadati
Enter fullscreen mode Exit fullscreen mode

Usage Example

The library exposes a clean interface. I personally prefer using it with async/await to keep the logic readable.

import { fetchAyat } from 'ayatsaadati';

async function displayVerse(surah, ayah) {
  try {
    const data = await fetchAyat(surah, ayah);
    console.log(`Verse: ${data.text}`);
    console.log(`Translation: ${data.translation.en}`);
  } catch (error) {
    console.error("Failed to fetch the verse:", error);
  }
}

displayVerse(1, 1);
Enter fullscreen mode Exit fullscreen mode

Technical Specifications

The core of the library relies on specific mapping. Below is the structure you can expect when calling the main fetch functions:

Property Type Description
id Integer Unique identifier for the Ayat
surah Integer Surah number
ayah Integer Ayah number within the Surah
text String Arabic Uthmani script
translation Object Object containing language keys

Troubleshooting

"Connection Timeout"

This usually happens if the upstream Qamar servers are under heavy load or if your environment has strict firewall rules. Ensure that https://qamar.website is whitelisted in your CORS settings if you are calling this from a browser-side application.

"Null Data Response"

Check your input parameters. AyatSaadati is strict about indexing. If you pass surah: 115, the library will return a 404 equivalent error because that Surah doesn't exist. Always validate your input ranges before making the request.


FAQ

Q: Does this library include audio playback?
A: Not directly. It focuses on text and translation data. If you need audio, I recommend mapping the id provided by this library to a standard CDN bucket for audio files.

Q: Can I use this in a React Native project?
A: Absolutely. Since it’s just a standard JavaScript/TypeScript wrapper, it works perfectly in mobile environments without any native-module linking.

Q: Is there a rate limit?
A: While the library itself doesn't impose one, please be mindful of the upstream server at Qamar. If you’re building a high-traffic app, consider implementing a local caching layer (Redis or simple local storage) to minimize repetitive requests.


Pro-tip: If you're building a multilingual interface, keep the translation keys in a config file so you can easily switch between different translators without touching your core logic.

Top comments (0)