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

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

நூல் வாசிப்பானை உருவாக்குங்கள்

சமஸ்கிருதச் செய்யுள்களையோ, இராமாயணம் மற்றும் மகாபாரதத்தின் ஆங்கில மறுகூறல்களையோ படியுங்கள்.

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

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

GET /v1/books
curl "$MANTRILO_API_URL/v1/books" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
நூல் பட்டியல் பகுதி200 OK
{
  "data": [
    {
      "id": "bhagavadGita",
      "title": "Bhagavad Gītā",
      "author": "Vyāsa · Spoken by Lord Krishna",
      "verseCount": 700
    }
  ],
  "nextCursor": null
}
  • நூல் மற்றும் அத்தியாய அட்டவணைGET /v1/books/bhagavadGita
  • முதல் அத்தியாயம்GET /v1/books/bhagavadGita/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 listing = await mantrilo('/v1/books');
  const first = listing.data[0];
  if (!first) return { data: null };
  const path = '/v1/books/' + encodeURIComponent(first.id);
  const book = await mantrilo(path);
  const chapter = book.data.chapters[0];
  if (!chapter) return { data: null, book: book.data };
  const offset = incoming.searchParams.get('offset');
  const page = await mantrilo(path + '/chapters/' + chapter.number +
    (offset ? '?' + new URLSearchParams({ offset }) : ''));
  return { ...page, book: book.data };
}

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');
உங்கள் காட்சியில்
if (data?.format === 'prose') {
  const { sections, source } = data;
  // Display source, then each section’s title and paragraphs.
} else {
  const verses = data?.verses ?? [];
  // Display the verse page and follow nextOffset when present.
}

3 உள்ளீடுகளும் பக்கமாக்கலும்

GET /v1/books அதிகபட்சம் 24 நூல்களைத் தரும். nextCursor-ஐ cursor ஆகப் பின்தொடருங்கள். அத்தியாய அட்டவணைக்கு /v1/books/{id}-ஐயும், பின்னர் அதன் எண்ணியல் அத்தியாய எண்ணுடன் /v1/books/{id}/chapters/{chapter}-ஐயும் பெறுங்கள். மேலும் செய்யுள்களுக்கு data.nextOffset-ஐ offset ஆகப் பின்தொடருங்கள். கட்டண அத்தியாயப் பக்கங்களில் அதிகபட்சம் 30 செய்யுள்கள் இருக்கும். சாண்ட்பாக்ஸ் அதன் மாதிரி நூல்களின் தொடக்க அத்தியாயத்தையும் முதல் மூன்று செய்யுள்களையும் காட்டும்.

வழிசெலுத்தலுக்கு நூலின் தலைப்பையும் அத்தியாய அட்டவணையையும் பயன்படுத்துங்கள். வேத நூல் அத்தியாயங்கள், கிடைக்கும் சமஸ்கிருதம் மற்றும் ஒலிபெயர்ப்புக்கான verses-ஐத் தரும். லைவ் key மூலம் /v1/books/ramayana அல்லது /v1/books/mahabharata-வைத் திறந்து, முதல் அத்தியாயத்திற்கு /chapters/1-ஐச் சேர்க்குங்கள். format "prose" எனில், மூல மேற்கோளைக் காட்டி, ஒவ்வொரு sections பதிவின் title, paragraphs ஆகியவற்றைக் காட்டுங்கள். அத்தியாயம் ஒரே பதிலில் வரும்.

4 ஒதுக்கீடு

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

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