गाइडहरू · पुस्तकहरू
उपनिषद्हरू आफ्नो एपमा लोड गर्नुहोस्
एउटा सङ्ग्रहलाई सिधै कल गर्नुहोस्, पेजअनुसार हेर्नुहोस्, अनि पुस्तक, अध्याय वा श्लोक खोल्नुहोस्।
यो रिक्वेस्ट sandbox मा चलाएर हेर्नुहोस्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 सर्भरले तपाईंको एपले कल गर्न मिल्ने एउटा route खोल्छ।
// 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 चल्छ। यस सङ्ग्रहका लागि sandbox key ले ईशावास्य उपनिषद् मात्र दिन्छ, र nextCursor null हुन्छ। सशुल्क key ले उपलब्ध सङ्ग्रह पेजअनुसार हेर्न सक्छ। नमुना तोकिएको नभएका सङ्ग्रहले खाली sandbox पेज दिन्छन्।
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 प्रयोग हुन्छ।
