गाइड · मंत्र
खोजने योग्य मंत्र लाइब्रेरी बनाएँ
मंत्रों और श्लोकों की सूची दिखाएँ, देवता के अनुसार फ़िल्टर करें और लोड किए गए शीर्षकों में खोजें।
यह रिक्वेस्ट सैंडबॉक्स में आज़माएँ1 काम करने वाली रिक्वेस्ट भेजें
curl "$MANTRILO_API_URL/v1/mantras?limit=1" \
-H "Authorization: Bearer $MANTRILO_API_KEY"{
"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 सर्वर एक रूट देता है जिसे आपका ऐप कॉल कर सकता है।
// 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 (देवता की ID, जैसे annapurna) का उपयोग करें। Mantras रूट श्लोक भी देता है। API में फ़ुल-टेक्स्ट खोज का कोई पैरामीटर नहीं है। उदाहरण लोड किए गए एक पेज को शीर्षक से और चाहें तो ऑडियो की उपलब्धता से फ़िल्टर करता है। पूरे कैटलॉग में खोज के लिए, अनुमत सामग्री को अपने बैकएंड में इंडेक्स करें।
data[].title, deity.name और verseCount दिखाएँ। अगले पेज के लिए nextCursor का उपयोग करें। किसी पंक्ति को खोलने के लिए उसकी id को GET /v1/mantras/{id} में पास करें।
4 कोटा
हर सफल पेज, देवता-फ़िल्टर रिक्वेस्ट और विवरण फ़ेच में एक रिक्वेस्ट लगती है। पहले से लोड किए गए परिणामों में खोजने या ऑडियो फ़िल्टर करने, या Mantrilo को कॉल किए बिना पूरा रिस्पॉन्स अपने कैश से देने में Mantrilo की कोई रिक्वेस्ट नहीं लगती।
रिक्वेस्ट base URL को MANTRILO_API_URL से पढ़ती हैं। सर्वर उदाहरण में यह न मिलने पर https://api.mantrilo.com का उपयोग होता है।
