गाइड · पुस्तकें
उपनिषदों को अपने ऐप में लोड करें
किसी एक संग्रह को सीधे कॉल करें, उसके पेज पलटें, फिर कोई पुस्तक, अध्याय या श्लोक खोलें।
यह रिक्वेस्ट सैंडबॉक्स में आज़माएँ1 काम करने वाली रिक्वेस्ट भेजें
curl "$MANTRILO_API_URL/v1/books?collection=upanishads&limit=3" \
-H "Authorization: Bearer $MANTRILO_API_KEY"{
"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 · 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 संग्रह पर वापस जाने वाले लिंक के लिए भी काम करती है। सैंडबॉक्स keys इस संग्रह के लिए ईशोपनिषद देती हैं और nextCursor null रहता है। सशुल्क keys उपलब्ध संग्रह के सभी पेज देख सकती हैं। जिन संग्रहों का कोई तय नमूना नहीं है, वे सैंडबॉक्स में खाली पेज लौटाते हैं।
data[].title और description की सूची दिखाएँ, फिर GET /v1/books/{id} से पुस्तक खोलें। उसका chapters[] GET /v1/books/{id}/chapters/{chapter} के लिए अध्याय संख्याएँ देता है, जिसके verses[] में हर श्लोक की संख्या होती है।
4 कोटा
हर संग्रह पेज, पुस्तक इंडेक्स और अध्याय पेज में एक रिक्वेस्ट लगती है। बारह पुस्तकों वाले संग्रह को एक बार में तीन पुस्तकें लेकर पलटने में चार रिक्वेस्ट लगती हैं।
रिक्वेस्ट base URL को MANTRILO_API_URL से पढ़ती हैं। सर्वर उदाहरण में यह न मिलने पर https://api.mantrilo.com का उपयोग होता है।
