ਸਮੱਗਰੀ 'ਤੇ ਜਾਓ
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 ਕੋਟਾ

ਸਫਲ ਪੁਸਤਕ ਸੂਚੀ, ਪੁਸਤਕ ਵੇਰਵਾ ਜਾਂ ਅਧਿਆਇ ਪੰਨਾ, ਹਰ ਇੱਕ ਇੱਕ ਬੇਨਤੀ ਵਰਤਦਾ ਹੈ। ਹੇਠਾਂ ਦਿੱਤੀ ਪੂਰੀ ਉਦਾਹਰਨ ਤਿੰਨ ਕਾਲਾਂ ਕਰਦੀ ਹੈ। ਜਿੱਥੇ ਢੁਕਵਾਂ ਹੋਵੇ, ਕੈਸ਼ ਕੀਤੀਆਂ ਸੂਚੀਆਂ ਅਤੇ ਪੰਨੇ ਦੁਬਾਰਾ ਵਰਤੋ।

ਬੇਨਤੀਆਂ ਬੇਸ URL MANTRILO_API_URL ਤੋਂ ਪੜ੍ਹਦੀਆਂ ਹਨ। ਸਰਵਰ ਉਦਾਹਰਨ ਵਿੱਚ ਇਸ ਦੇ ਨਾ ਹੋਣ 'ਤੇ https://api.mantrilo.com ਵਰਤਿਆ ਜਾਂਦਾ ਹੈ।