గైడ్లు · గ్రంథాలు
ఉపనిషత్తులను మీ యాప్లోకి లోడ్ చేయండి
ఒక కలెక్షన్ను నేరుగా పిలిచి, దాని పేజీల గుండా వెళ్లి, ఆపై ఒక గ్రంథాన్ని, అధ్యాయాన్ని లేదా శ్లోకాన్ని తెరవండి.
ఈ రిక్వెస్ట్ను శాండ్బాక్స్లో ప్రయత్నించండి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 కోటా
ప్రతి కలెక్షన్ పేజీ, గ్రంథ సూచిక, అధ్యాయ పేజీ ఒక్కో రిక్వెస్ట్ను ఉపయోగిస్తుంది. పన్నెండు గ్రంథాల కలెక్షన్లో ఒకేసారి మూడు గ్రంథాల చొప్పున పేజీలు తిప్పితే నాలుగు రిక్వెస్ట్లు ఖర్చవుతాయి.
రిక్వెస్ట్లు బేస్ URL ను MANTRILO_API_URL నుంచి చదువుతాయి. సర్వర్ ఉదాహరణ ప్రత్యామ్నాయంగా https://api.mantrilo.com ను ఉపయోగిస్తుంది.
