মূল কনটেন্টে যান
API key নিন

গাইড · মন্ত্র

দৈনিক মন্ত্র বা বিশেষ শ্লোক যোগ করুন

একটি বাছাই করা মন্ত্র আনুন এবং তার মূল সংস্কৃত ও প্রতিবর্ণীকরণ দেখান।

স্যান্ডবক্সে এই রিকোয়েস্টটি চালিয়ে দেখুন

1 চালু একটি রিকোয়েস্ট পাঠান

GET /v1/mantras/annapurna-aham-vaishvanaro-bhuthva
curl "$MANTRILO_API_URL/v1/mantras/annapurna-aham-vaishvanaro-bhuthva" \
  -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"
    },
    "verses": [
      {
        "number": 1,
        "title": "Aham Vaishvanaro Bhuthva – Verse 1",
        "sanskrit": "अहं वैश्वानरो भूत्वा प्राणिनां देहमाश्रितः\nप्राणापान समायुक्तः पचाम्यन्नं चतुर्विधम्",
        "transliteration": "ahaṃ vaiśvānaro bhūtvā prāṇināṃ dehamāśritaḥ\nprāṇāpāna samāyuktaḥ pacāmyannaṃ caturvidham",
        "translation": null,
        "wordMeanings": []
      }
    ]
  },
  "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) {
  return mantrilo("/v1/mantras/annapurna-aham-vaishvanaro-bhuthva");
}

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 featured = { title: data.title, verse: data.verses?.[0] };

3 ইনপুট ও পেজিনেশন

ক্যাটালগের স্থায়ী id ব্যবহার করুন। বিশেষ ID-টি আপনার অ্যাপে বেছে নিন বা শিডিউল করুন। API বাছাই করা এন্ট্রিটি দেয়।

data.title ও verses অ্যারে রেন্ডার করুন। sanskrit ও transliteration থাকলে দেখান। translation ফিল্ডটি এখন null।

4 কোটা

প্রতিটি সফল বিস্তারিত ফেচে একটি রিকোয়েস্ট খরচ হয়। আপনার ব্যাকএন্ড ক্যাশে আগে থেকে থাকা এন্ট্রি আবার ব্যবহার করলে বাড়তি কোনো রিকোয়েস্ট লাগে না।

রিকোয়েস্টগুলো MANTRILO_API_URL থেকে বেস URL নেয়। সার্ভারের উদাহরণে তা না থাকলে https://api.mantrilo.com ব্যবহার হয়।