ଗାଇଡ୍ · ପୁସ୍ତକ
ଏକ ପୁସ୍ତକ ରିଡର୍ ତିଆରି କରନ୍ତୁ
ସଂସ୍କୃତ ଶ୍ଲୋକ କିମ୍ବା ରାମାୟଣ ଓ ମହାଭାରତର ଇଂରାଜୀ ପୁନର୍କଥନ ପଢ଼ନ୍ତୁ।
ସ୍ୟାଣ୍ଡବକ୍ସରେ ଏହି ଅନୁରୋଧ ଚେଷ୍ଟା କରନ୍ତୁ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 ରୁ ବେସ୍ URL ପଢ଼େ। ସର୍ଭର ଉଦାହରଣଟି ଡିଫଲ୍ଟ ଭାବେ https://api.mantrilo.com ବ୍ୟବହାର କରେ।
