सामग्रीमा जानुहोस्
API key लिनुहोस्

गाइडहरू · मन्त्रहरू

खोज्न मिल्ने मन्त्र लाइब्रेरी बनाउनुहोस्

मन्त्र र श्लोकहरूको सूची लिनुहोस्, देवताअनुसार फिल्टर गर्नुहोस् र लोड गरिएका शीर्षकहरूमा खोज्नुहोस्।

यो रिक्वेस्ट sandbox मा चलाएर हेर्नुहोस्

1 चल्ने रिक्वेस्ट बनाउनुहोस्

GET /v1/mantras?limit=1
curl "$MANTRILO_API_URL/v1/mantras?limit=1" \
  -H "Authorization: Bearer $MANTRILO_API_KEY"
Sandbox सूचीको उदाहरण200 OK
{
  "data": [
    {
      "id": "annapurna-aham-vaishvanaro-bhuthva",
      "title": "Aham Vaishvanaro Bhuthva",
      "deity": {
        "id": "annapurna",
        "name": "Lord Annapurna"
      },
      "category": "Annapurna Stotras",
      "source": "Sanatana Shastras",
      "description": "Aham Vaishvanaro Bhutva means \"I, having become the universal fire,\" and in Bhagavad Gita 15.14 Krishna says he lives in every body and digests its food. United with the prana and apana breaths, this inner fire cooks the four kinds of food: chewed, swallowed, licked and sucked. Families often say it before a meal to treat eating as an offering.",
      "verseCount": 1,
      "audio": {
        "href": "/v1/mantras/annapurna-aham-vaishvanaro-bhuthva/audio"
      }
    }
  ],
  "nextCursor": "YW5uYXB1cm5hLWFoYW0tdmFpc2h2YW5hcm8tYmh1dGh2YQ",
  "sandbox": true
}

2 यसलाई आफ्नो सर्भरबाट कल गर्नुहोस्

key आफ्नो ब्याकइन्डमै राख्नुहोस् र एपमा सामग्री मात्र फर्काउनुहोस्। यो Node.js सर्भरले तपाईंको एपले कल गर्न मिल्ने एउटा route खोल्छ।

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({ limit: '1' });
  for (const field of ['cursor', 'deity']) {
    const value = incoming.searchParams.get(field);
    if (value) params.set(field, value);
  }
  const page = await mantrilo('/v1/mantras?' + params);
  const query = (incoming.searchParams.get('q') ?? '').trim().toLowerCase();
  const audio = incoming.searchParams.get('audio'); // 'with' or 'without'
  return {
    ...page,
    data: page.data.filter(item =>
      (item.title ?? '').toLowerCase().includes(query) &&
      (audio === 'with' ? !!item.audio : audio === 'without' ? !item.audio : true)
    ),
  };
}

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 titles = data.map(item => item.title);

3 इनपुट र पेजिनेसन

limit (1–100, पूर्वनिर्धारित 20), cursor (अघिल्लो nextCursor) र ऐच्छिक deity (annapurna जस्तो देवता ID) प्रयोग गर्नुहोस्। Mantras route ले श्लोकहरू पनि दिन्छ। API मा पूर्ण-पाठ खोजको कुनै प्यारामिटर छैन। उदाहरणले लोड गरिएको एउटा पेजलाई शीर्षकअनुसार र चाहेमा अडियो उपलब्धताअनुसार फिल्टर गर्छ। पूरै क्याटलगमा खोज्न अनुमति भएको सामग्री आफ्नो ब्याकइन्डमा इन्डेक्स गर्नुहोस्।

data[].title, deity.name र verseCount देखाउनुहोस्। अर्को पेजका लागि nextCursor प्रयोग गर्नुहोस्। कुनै पङ्क्ति खोल्न त्यसको id GET /v1/mantras/{id} मा पठाउनुहोस्।

4 कोटा

हरेक सफल पेज, देवता-फिल्टर रिक्वेस्ट र विवरण फेचले एक रिक्वेस्ट खर्च गर्छ। पहिल्यै लोड भएका नतिजामा खोज्दा वा अडियो फिल्टर गर्दा, वा Mantrilo लाई कल नगरी आफ्नै क्यासबाट पूरै रेस्पोन्स दिँदा Mantrilo को कुनै रिक्वेस्ट खर्च हुँदैन।

रिक्वेस्टहरूले base URL MANTRILO_API_URL बाट पढ्छन्। सर्भरको उदाहरणमा त्यो नभए https://api.mantrilo.com प्रयोग हुन्छ।