કન્ટેન્ટ પર જાઓ
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 વાપરે છે.