গাইড · পুথি
পুথি পঢ়া এপ এটা বনাওক
সংস্কৃত শ্লোক বা ৰামায়ণ আৰু মহাভাৰতৰ ইংৰাজী পুনৰ্কথন পঢ়ক।
এই ৰিকুৱেষ্টটো ছেণ্ডবক্সত চেষ্টা কৰক1 চলি থকা এটা ৰিকুৱেষ্ট কৰক
curl "$MANTRILO_API_URL/v1/books" \
-H "Authorization: Bearer $MANTRILO_API_KEY"{
"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 · 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 কোটা
সফল পুথিৰ তালিকা, পুথিৰ বিৱৰণ বা অধ্যায়ৰ পৃষ্ঠা প্ৰতিটোত এটাকৈ ৰিকুৱেষ্ট খৰচ হয়। তলৰ সম্পূৰ্ণ উদাহৰণটোৱে তিনিটা কল কৰে। উপযুক্ত হ'লে কেচ কৰা সূচী আৰু পৃষ্ঠা পুনৰ ব্যৱহাৰ কৰক।
ৰিকুৱেষ্টবোৰে MANTRILO_API_URLৰ পৰা base URL পঢ়ে। ছাৰ্ভাৰৰ উদাহৰণটোৱে বিকল্প হিচাপে https://api.mantrilo.com ব্যৱহাৰ কৰে।
