உள்ளடக்கத்திற்குச் செல்லுங்கள்
API key-ஐப் பெறுங்கள்

வழிகாட்டிகள் · நூல்கள்

உபநிடதங்களை உங்கள் ஆப்பில் ஏற்றுங்கள்

ஒரு தொகுப்பை நேரடியாக அழைத்து, அதன் பக்கங்களைப் புரட்டி, பின்னர் ஒரு நூல், அத்தியாயம் அல்லது செய்யுளைத் திறங்கள்.

இந்தக் கோரிக்கையைச் சாண்ட்பாக்ஸில் முயன்று பாருங்கள்

1 செயல்படும் கோரிக்கையை உருவாக்குங்கள்

GET /v1/books?collection=upanishads&limit=3
curl "$MANTRILO_API_URL/v1/books?collection=upanishads&limit=3" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
சாண்ட்பாக்ஸ் தொகுப்புப் பதில்200 OK
{
  "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
// 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 ஒதுக்கீடு

ஒவ்வொரு தொகுப்புப் பக்கமும், நூல் அட்டவணையும், அத்தியாயப் பக்கமும் ஒரு கோரிக்கையைப் பயன்படுத்தும். பன்னிரண்டு நூல்கள் உள்ள தொகுப்பில் ஒரு முறைக்கு மூன்று நூல்களாகப் பக்கம் புரட்டினால் நான்கு கோரிக்கைகள் செலவாகும்.

கோரிக்கைகள் base URL-ஐ MANTRILO_API_URL-இலிருந்து படிக்கின்றன. சர்வர் எடுத்துக்காட்டு மாற்றாக https://api.mantrilo.com-ஐப் பயன்படுத்தும்.