ഗൈഡുകൾ · പുസ്തകങ്ങൾ
ഉപനിഷത്തുകൾ നിങ്ങളുടെ ആപ്പിലേക്ക് ലോഡ് ചെയ്യുക
ഒരു ശേഖരം നേരിട്ട് വിളിക്കുക, അതിലൂടെ പേജ് ചെയ്യുക, തുടർന്ന് ഒരു പുസ്തകമോ അധ്യായമോ ശ്ലോകമോ തുറക്കുക.
ഈ റിക്വസ്റ്റ് സാൻഡ്ബോക്സിൽ പരീക്ഷിക്കുക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 നിങ്ങളുടെ സെർവറിൽ നിന്ന് വിളിക്കുക
കീ നിങ്ങളുടെ ബാക്കെൻഡിൽ സൂക്ഷിച്ച് ഉള്ളടക്കം മാത്രം ആപ്പിലേക്ക് തിരികെ നൽകുക. ഈ 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 ഉപയോഗിക്കാം. ഈ ശേഖരത്തിന് സാൻഡ്ബോക്സ് കീകൾ ഈശോപനിഷത്ത് മാത്രം നൽകുന്നു, nextCursor null ആയിരിക്കും. പണമടച്ചുള്ള കീകൾ ഉപയോഗിച്ച് ലഭ്യമായ ശേഖരം മുഴുവൻ പേജ് ചെയ്യാം. നിശ്ചിത സാമ്പിൾ ഇല്ലാത്ത ശേഖരങ്ങൾ ശൂന്യമായ സാൻഡ്ബോക്സ് പേജ് നൽകുന്നു.
data[].title, description എന്നിവ ലിസ്റ്റ് ചെയ്യുക, തുടർന്ന് GET /v1/books/{id} ഉപയോഗിച്ച് ഒരു പുസ്തകം തുറക്കുക. അതിലെ chapters[], GET /v1/books/{id}/chapters/{chapter} എന്നതിനുള്ള അധ്യായ നമ്പറുകൾ നൽകുന്നു; അതിന്റെ verses[] ഓരോ ശ്ലോകത്തിന്റെയും നമ്പർ ഉൾക്കൊള്ളുന്നു.
4 ക്വോട്ട
ഓരോ ശേഖര പേജും പുസ്തക ഇൻഡക്സും അധ്യായ പേജും ഓരോ റിക്വസ്റ്റ് ഉപയോഗിക്കുന്നു. പന്ത്രണ്ട് പുസ്തകങ്ങളുള്ള ഒരു ശേഖരത്തിലൂടെ മൂന്ന് പുസ്തകം വീതം പേജ് ചെയ്യാൻ നാല് റിക്വസ്റ്റുകൾ വേണം.
റിക്വസ്റ്റുകൾ ബേസ് URL MANTRILO_API_URL-ൽ നിന്ന് വായിക്കുന്നു. സെർവർ ഉദാഹരണം ബദലായി https://api.mantrilo.com ഉപയോഗിക്കുന്നു.
