मुख्य मजकुराकडे जा
API key मिळवा

मार्गदर्शिका · ग्रंथ

उपनिषदे तुमच्या ॲपमध्ये लोड करा

एखादा संग्रह थेट कॉल करा, त्याची पाने पाहा, मग ग्रंथ, अध्याय किंवा श्लोक उघडा.

ही रिक्वेस्ट सँडबॉक्समध्ये वापरून पाहा

1 चालणारी रिक्वेस्ट पाठवा

GET /v1/books?collection=upanishads&limit=3
curl "$MANTRILO_API_URL/v1/books?collection=upanishads&limit=3" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
सँडबॉक्स संग्रहाचा रिस्पॉन्स200 OK
{
  "data": [
    {
      "id": "ishaUpanishad",
      "title": "Īśāvāsya Upaniṣad",
      "author": "Vedic Rishis",
      "category": null,
      "subcategory": null,
      "collection": {
        "id": "upanishads",
        "name": "Upanishads"
      },
      "description": "One of the shortest and most profound Upanishads, revealing the nature of the Supreme Lord who pervades all.",
      "verseCount": 18
    }
  ],
  "nextCursor": null,
  "sandbox": true,
  "requestId": "request-id"
}
  • ग्रंथ आणि अध्याय अनुक्रमणिकाGET /v1/books/ishaUpanishad
  • पहिला अध्यायGET /v1/books/ishaUpanishad/chapters/1

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({ collection: 'upanishads', limit: '3' });
  const cursor = incoming.searchParams.get('cursor');
  if (cursor) params.set('cursor', cursor);
  return mantrilo('/v1/books?' + params);
}

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 books = data.map(book => ({ id: book.id, title: book.title, description: book.description }));

3 इनपुट आणि पेजिनेशन

collection हा संग्रहाचा id आहे: upanishads, bhagavad-gita, advaita-vedanta-prakarana-granthas, vedanta किंवा yoga. limit 1–100 असतो (डीफॉल्ट 24). पुढच्या पानासाठी nextCursor हा cursor म्हणून पाठवा; शेवटच्या पानावर तो null असतो. रिस्पॉन्समधील प्रत्येक ग्रंथात collection.id असतो, त्यामुळे संग्रहाकडे परत जाणाऱ्या लिंकसाठीही तोच id चालतो. या संग्रहासाठी सँडबॉक्स key ईशावास्य उपनिषद देतात आणि nextCursor null असतो. सशुल्क key उपलब्ध संपूर्ण संग्रहाची पाने पाहू शकतात. ज्या संग्रहांसाठी नमुना ठरवलेला नाही, त्यांचे सँडबॉक्स पान रिकामे येते.

data[].title आणि description ची यादी दाखवा, मग GET /v1/books/{id} ने ग्रंथ उघडा. त्यातील chapters[] मधून GET /v1/books/{id}/chapters/{chapter} साठी अध्याय क्रमांक मिळतात, आणि त्याच्या verses[] मध्ये प्रत्येक श्लोकाचा क्रमांक असतो.

4 कोटा

प्रत्येक संग्रह-पान, ग्रंथाची अनुक्रमणिका आणि अध्याय-पान यासाठी एक रिक्वेस्ट वापरली जाते. बारा ग्रंथांच्या संग्रहात एका वेळी तीन ग्रंथ पाहिल्यास चार रिक्वेस्ट लागतात.

रिक्वेस्ट बेस URL MANTRILO_API_URL मधून घेतात. ते नसल्यास सर्व्हर उदाहरण https://api.mantrilo.com वापरते.