ਗਾਈਡਾਂ · ਪੁਸਤਕਾਂ
ਆਪਣੀ ਐਪ ਵਿੱਚ ਉਪਨਿਸ਼ਦ ਲੋਡ ਕਰੋ
ਇੱਕ ਸੰਗ੍ਰਹਿ ਨੂੰ ਸਿੱਧਾ ਕਾਲ ਕਰੋ, ਉਸ ਦੇ ਪੰਨੇ ਵੇਖੋ, ਫਿਰ ਕੋਈ ਪੁਸਤਕ, ਅਧਿਆਇ ਜਾਂ ਸ਼ਲੋਕ ਖੋਲ੍ਹੋ।
ਇਹ ਬੇਨਤੀ ਸੈਂਡਬਾਕਸ ਵਿੱਚ ਅਜ਼ਮਾਓ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 ਸੰਗ੍ਰਹਿ ਵੱਲ ਵਾਪਸੀ ਲਿੰਕਾਂ ਲਈ ਵੀ ਕੰਮ ਕਰਦੀ ਹੈ। ਸੈਂਡਬਾਕਸ 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 ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।
