@x12i/mdreports-api-client
v0.4.0
Published
Typed fetch client for the Markdown Reports Studio HTTP API.
Maintainers
Readme
@x12i/mdreports-api-client
Typed fetch client for the Markdown Reports Studio HTTP API (@x12i/mdreports-api).
Install
npm install @x12i/mdreports-api-clientUsage
import { ApiClient, ApiError } from "@x12i/mdreports-api-client";
const client = new ApiClient({
baseUrl: "http://localhost:6460",
apiKey: process.env.MDREPORTS_API_KEY // optional; required if the server sets MDREPORTS_API_KEY
});
const templates = await client.listTemplates();
const { html, title } = await client.renderHtml("# Hello", "clean-report");
const pdf = await client.renderPdf("# Hello", "clean-report");
const docx = await client.renderDocx("# Hello", "clean-report");
const pptx = await client.renderPptx("# Hello\n\nBody", "clean-report");
await client.createTemplateFromHtml({
id: "my-report",
name: "My Report",
layoutHtml: "<!doctype html><html><head></head><body><!--CONTENT--></body></html>",
stylesCss: "body { font-family: sans-serif; }"
});
try {
await client.getTemplate("missing");
} catch (err) {
if (err instanceof ApiError) {
console.error(err.status, err.code, err.message);
}
}Methods
| Method | API |
| --- | --- |
| listTemplates() | GET /templates |
| getTemplate(id) | GET /templates/:id |
| createTemplateFromHtml(input) | POST /templates/from-html |
| createTemplateFromImage(input) | POST /templates/from-image (multipart) |
| updateTemplate(id, patch) | PATCH /templates/:id |
| deleteTemplate(id) | DELETE /templates/:id |
| renderHtml(...) | POST /render/html |
| renderPdf(...) | POST /render/pdf → Blob |
| renderDocx(...) | POST /render/docx → Blob |
| renderPptx(...) | POST /render/pptx → Blob |
Default baseUrl is http://localhost:6460 (org port-map zone default for this repo).
