مواد پر جائیں
API key حاصل کریں

گائیڈز · منتر

تلاش کے قابل منتر لائبریری بنائیں

منتروں اور شلوکوں کی فہرست بنائیں، دیوتا کے لحاظ سے فلٹر کریں، اور لوڈ کیے گئے عنوانات میں تلاش کریں۔

یہ درخواست سینڈ باکس میں آزمائیں

1 ایک کام کرنے والی درخواست بھیجیں

GET /v1/mantras?limit=1
curl "$MANTRILO_API_URL/v1/mantras?limit=1" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
سینڈ باکس فہرست کی مثال200 OK
{
  "data": [
    {
      "id": "annapurna-aham-vaishvanaro-bhuthva",
      "title": "Aham Vaishvanaro Bhuthva",
      "deity": {
        "id": "annapurna",
        "name": "Lord Annapurna"
      },
      "category": "Annapurna Stotras",
      "source": "Sanatana Shastras",
      "description": "Aham Vaishvanaro Bhutva means \"I, having become the universal fire,\" and in Bhagavad Gita 15.14 Krishna says he lives in every body and digests its food. United with the prana and apana breaths, this inner fire cooks the four kinds of food: chewed, swallowed, licked and sucked. Families often say it before a meal to treat eating as an offering.",
      "verseCount": 1,
      "audio": {
        "href": "/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio"
      }
    }
  ],
  "nextCursor": "YW5uYXB1cm5hLWFoYW0tdmFpc2h2YW5hcm8tYmh1dGh2YQ",
  "sandbox": true
}

2 اسے اپنے سرور سے کال کریں

key اپنے بیک اینڈ میں رکھیں اور اپنی ایپ کو صرف مواد واپس کریں۔ یہ Node.js سرور ایک روٹ فراہم کرتا ہے جسے آپ کی ایپ کال کر سکتی ہے۔

server.mjs
// server.mjs · Node.js 22+
import { createServer } from 'node:http';

const apiKey = process.env.MANTRILO_API_KEY;
if (!apiKey) throw new Error('Set MANTRILO_API_KEY on your server.');
const base = process.env.MANTRILO_API_URL ?? "https://api.mantrilo.com";

async function mantrilo(path, input) {
  const response = await fetch(base + path, {
    method: input ? 'POST' : 'GET',
    headers: {
      Authorization: 'Bearer ' + apiKey,
      ...(input ? { 'Content-Type': 'application/json' } : {}),
    },
    ...(input ? { body: JSON.stringify(input) } : {}),
    signal: AbortSignal.timeout(20000),
    redirect: 'error',
  });
  const result = await response.json();
  if (!response.ok) throw Object.assign(new Error('Mantrilo request failed'), {
    status: response.status, requestId: result.requestId,
  });
  return result;
}

async function load(incoming) {
  const params = new URLSearchParams({ limit: '1' });
  for (const field of ['cursor', 'deity']) {
    const value = incoming.searchParams.get(field);
    if (value) params.set(field, value);
  }
  const page = await mantrilo('/v1/mantras?' + params);
  const query = (incoming.searchParams.get('q') ?? '').trim().toLowerCase();
  const audio = incoming.searchParams.get('audio'); // 'with' or 'without'
  return {
    ...page,
    data: page.data.filter(item =>
      (item.title ?? '').toLowerCase().includes(query) &&
      (audio === 'with' ? !!item.audio : audio === 'without' ? !item.audio : true)
    ),
  };
}

createServer(async (req, res) => {
  const incoming = new URL(req.url, 'http://localhost');
  res.setHeader('Content-Type', 'application/json');
  if (req.method !== 'GET' || incoming.pathname !== '/api/mantrilo-guide') {
    res.writeHead(404).end(JSON.stringify({ error: 'Not found' }));
    return;
  }
  try {
    const result = await load(incoming);
    res.end(JSON.stringify(result));
  } catch (error) {
    res.writeHead(error.status ?? 502).end(JSON.stringify({
      error: 'Could not load this content',
      requestId: error.requestId,
    }));
  }
}).listen(3000, '127.0.0.1');
آپ کے منظر میں
const titles = data.map(item => item.title);

3 ان پٹ اور صفحہ بندی

limit (1–100، طے شدہ 20)، cursor (پچھلا nextCursor) اور اختیاری deity (دیوتا کی ID، جیسے annapurna) استعمال کریں۔ Mantras روٹ شلوک بھی فراہم کرتا ہے۔ API میں مکمل متن کی تلاش کا کوئی پیرامیٹر نہیں ہے۔ مثال ایک لوڈ شدہ صفحے کو عنوان کے لحاظ سے، اور اختیاری طور پر آڈیو کی دستیابی کے لحاظ سے، فلٹر کرتی ہے۔ پورے کیٹلاگ میں تلاش کے لیے اجازت یافتہ مواد کو اپنے بیک اینڈ میں انڈیکس کریں۔

data[].title، deity.name اور verseCount دکھائیں۔ اگلے صفحے کے لیے nextCursor استعمال کریں۔ کسی قطار کو کھولنے کے لیے اس کی id کو GET /v1/mantras/{id} میں بھیجیں۔

4 کوٹہ

ہر کامیاب صفحہ، دیوتا فلٹر والی درخواست اور تفصیل کی بازیافت ایک درخواست شمار ہوتی ہے۔ پہلے سے لوڈ شدہ نتائج میں تلاش کرنا یا آڈیو کے لحاظ سے فلٹر کرنا، یا Mantrilo کو کال کیے بغیر پورا رسپانس اپنے کیش سے دینا، Mantrilo کی کوئی درخواست استعمال نہیں کرتا۔

درخواستیں base URL کو MANTRILO_API_URL سے پڑھتی ہیں۔ سرور کی مثال متبادل کے طور پر https://api.mantrilo.com استعمال کرتی ہے۔