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