docfast/public/docs.html

396 lines
17 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DocFast API Documentation</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: #0a0a0a; color: #e0e0e0; line-height: 1.6; }
a { color: #6c9fff; text-decoration: none; }
a:hover { text-decoration: underline; }
.container { max-width: 900px; margin: 0 auto; padding: 2rem; }
header { border-bottom: 1px solid #222; padding-bottom: 1.5rem; margin-bottom: 2rem; }
header h1 { font-size: 2rem; margin-bottom: 0.5rem; }
header h1 a { color: #fff; }
header p { color: #888; font-size: 1.1rem; }
.base-url { background: #1a1a2e; border: 1px solid #333; border-radius: 6px; padding: 0.75rem 1rem; font-family: monospace; font-size: 0.95rem; margin-top: 1rem; color: #6c9fff; }
nav { background: #111; border: 1px solid #222; border-radius: 8px; padding: 1.25rem; margin-bottom: 2rem; }
nav h3 { margin-bottom: 0.75rem; color: #888; font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
nav ul { list-style: none; }
nav li { margin-bottom: 0.4rem; }
nav a { font-size: 0.95rem; }
nav .method { font-family: monospace; font-size: 0.8rem; font-weight: 600; padding: 2px 6px; border-radius: 3px; margin-right: 0.5rem; }
.method-post { background: #1a3a1a; color: #4caf50; }
.method-get { background: #1a2a3a; color: #6c9fff; }
section { margin-bottom: 3rem; }
section h2 { font-size: 1.5rem; border-bottom: 1px solid #222; padding-bottom: 0.5rem; margin-bottom: 1rem; }
section h3 { font-size: 1.2rem; margin: 2rem 0 0.75rem; color: #fff; }
.endpoint { background: #111; border: 1px solid #222; border-radius: 8px; padding: 1.5rem; margin-bottom: 2rem; }
.endpoint-header { display: flex; align-items: center; gap: 0.75rem; margin-bottom: 1rem; }
.endpoint-header .method { font-family: monospace; font-weight: 700; font-size: 0.85rem; padding: 4px 10px; border-radius: 4px; }
.endpoint-header .path { font-family: monospace; font-size: 1.05rem; color: #fff; }
table { width: 100%; border-collapse: collapse; margin: 0.75rem 0; }
th, td { text-align: left; padding: 0.5rem 0.75rem; border-bottom: 1px solid #1a1a1a; font-size: 0.9rem; }
th { color: #888; font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.03em; }
td code { background: #1a1a2e; padding: 2px 6px; border-radius: 3px; font-size: 0.85rem; }
.required { color: #ff6b6b; font-size: 0.75rem; }
pre { background: #0d0d1a; border: 1px solid #222; border-radius: 6px; padding: 1rem; overflow-x: auto; font-size: 0.85rem; line-height: 1.5; margin: 0.75rem 0; }
code { font-family: 'SF Mono', 'Fira Code', monospace; }
.comment { color: #666; }
.string { color: #a5d6a7; }
.key { color: #90caf9; }
.note { background: #1a1a2e; border-left: 3px solid #6c9fff; padding: 0.75rem 1rem; border-radius: 0 6px 6px 0; margin: 1rem 0; font-size: 0.9rem; }
.warning { background: #2a1a1a; border-left: 3px solid #ff6b6b; }
.status-codes { margin-top: 0.5rem; }
.status-codes span { display: inline-block; background: #1a1a2e; padding: 2px 8px; border-radius: 3px; font-family: monospace; font-size: 0.8rem; margin: 2px 4px 2px 0; }
.status-ok { color: #4caf50; }
.status-err { color: #ff6b6b; }
footer { border-top: 1px solid #222; padding-top: 1.5rem; margin-top: 3rem; text-align: center; color: #555; font-size: 0.85rem; }
</style>
</head>
<body>
<div class="container">
<header>
<h1><a href="/">DocFast</a> API Documentation</h1>
<p>Convert HTML, Markdown, and URLs to PDF. Built-in invoice &amp; receipt templates.</p>
<div class="base-url">Base URL: https://docfast.dev</div>
</header>
<nav>
<h3>Endpoints</h3>
<ul>
<li><a href="#auth">Authentication</a></li>
<li><a href="#html"><span class="method method-post">POST</span>/v1/convert/html</a></li>
<li><a href="#markdown"><span class="method method-post">POST</span>/v1/convert/markdown</a></li>
<li><a href="#url"><span class="method method-post">POST</span>/v1/convert/url</a></li>
<li><a href="#templates-list"><span class="method method-get">GET</span>/v1/templates</a></li>
<li><a href="#templates-render"><span class="method method-post">POST</span>/v1/templates/:id/render</a></li>
<li><a href="#signup"><span class="method method-post">POST</span>/v1/signup/free</a></li>
<li><a href="#errors">Error Handling</a></li>
</ul>
</nav>
<section id="auth">
<h2>Authentication</h2>
<p>All conversion and template endpoints require an API key. Pass it using either method:</p>
<pre>Authorization: Bearer df_free_your_api_key_here</pre>
<p>Or use the <code>X-API-Key</code> header:</p>
<pre>X-API-Key: df_free_your_api_key_here</pre>
<p style="margin-top:0.75rem">Get a free API key instantly — no credit card required:</p>
<pre>curl -X POST https://docfast.dev/v1/signup/free \
-H "Content-Type: application/json" \
-d '{"email": "you@example.com"}'</pre>
<div class="note">Free tier: <strong>100 PDFs/month</strong>. Pro ($9/mo): <strong>10,000 PDFs/month</strong>. Upgrade anytime at <a href="https://docfast.dev">docfast.dev</a>.</div>
</section>
<section id="html">
<h2>Convert HTML to PDF</h2>
<div class="endpoint">
<div class="endpoint-header">
<span class="method method-post">POST</span>
<span class="path">/v1/convert/html</span>
</div>
<p>Convert raw HTML (with optional CSS) to a PDF document.</p>
<h3>Request Body</h3>
<table>
<tr><th>Field</th><th>Type</th><th>Description</th></tr>
<tr><td><code>html</code> <span class="required">required</span></td><td>string</td><td>HTML content to convert</td></tr>
<tr><td><code>css</code></td><td>string</td><td>Additional CSS to inject</td></tr>
<tr><td><code>format</code></td><td>string</td><td>Page size: <code>A4</code> (default), <code>Letter</code>, <code>Legal</code>, <code>A3</code></td></tr>
<tr><td><code>landscape</code></td><td>boolean</td><td>Landscape orientation (default: false)</td></tr>
<tr><td><code>margin</code></td><td>object</td><td><code>{top, right, bottom, left}</code> in CSS units (default: 20mm each)</td></tr>
</table>
<h3>Example</h3>
<pre>curl -X POST https://docfast.dev/v1/convert/html \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"html": "&lt;h1&gt;Hello World&lt;/h1&gt;&lt;p&gt;Generated by DocFast.&lt;/p&gt;",
"css": "h1 { color: navy; }",
"format": "A4"
}' \
-o output.pdf</pre>
<h3>Response</h3>
<p><code>200 OK</code> — Returns the PDF as <code>application/pdf</code> binary stream.</p>
<div class="status-codes">
<span class="status-ok">200</span> PDF generated
<span class="status-err">400</span> Missing <code>html</code> field
<span class="status-err">401</span> Invalid/missing API key
<span class="status-err">429</span> Rate limited
</div>
</div>
</section>
<section id="markdown">
<h2>Convert Markdown to PDF</h2>
<div class="endpoint">
<div class="endpoint-header">
<span class="method method-post">POST</span>
<span class="path">/v1/convert/markdown</span>
</div>
<p>Convert Markdown to a styled PDF with syntax highlighting for code blocks.</p>
<h3>Request Body</h3>
<table>
<tr><th>Field</th><th>Type</th><th>Description</th></tr>
<tr><td><code>markdown</code> <span class="required">required</span></td><td>string</td><td>Markdown content</td></tr>
<tr><td><code>css</code></td><td>string</td><td>Additional CSS to inject</td></tr>
<tr><td><code>format</code></td><td>string</td><td>Page size (default: A4)</td></tr>
<tr><td><code>landscape</code></td><td>boolean</td><td>Landscape orientation</td></tr>
<tr><td><code>margin</code></td><td>object</td><td>Custom margins</td></tr>
</table>
<h3>Example</h3>
<pre>curl -X POST https://docfast.dev/v1/convert/markdown \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"markdown": "# Monthly Report\n\n## Summary\n\nRevenue increased by **15%** this quarter.\n\n| Metric | Value |\n|--------|-------|\n| Users | 1,234 |\n| MRR | $5,670 |"
}' \
-o report.pdf</pre>
<h3>Response</h3>
<p><code>200 OK</code> — Returns <code>application/pdf</code>.</p>
<div class="status-codes">
<span class="status-ok">200</span> PDF generated
<span class="status-err">400</span> Missing <code>markdown</code> field
<span class="status-err">401</span> Invalid/missing API key
</div>
</div>
</section>
<section id="url">
<h2>Convert URL to PDF</h2>
<div class="endpoint">
<div class="endpoint-header">
<span class="method method-post">POST</span>
<span class="path">/v1/convert/url</span>
</div>
<p>Navigate to a URL and convert the rendered page to PDF. Supports JavaScript-rendered pages.</p>
<h3>Request Body</h3>
<table>
<tr><th>Field</th><th>Type</th><th>Description</th></tr>
<tr><td><code>url</code> <span class="required">required</span></td><td>string</td><td>URL to convert (must start with http:// or https://)</td></tr>
<tr><td><code>waitUntil</code></td><td>string</td><td><code>load</code> (default), <code>domcontentloaded</code>, <code>networkidle0</code>, <code>networkidle2</code></td></tr>
<tr><td><code>format</code></td><td>string</td><td>Page size (default: A4)</td></tr>
<tr><td><code>landscape</code></td><td>boolean</td><td>Landscape orientation</td></tr>
<tr><td><code>margin</code></td><td>object</td><td>Custom margins</td></tr>
</table>
<h3>Example</h3>
<pre>curl -X POST https://docfast.dev/v1/convert/url \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com",
"waitUntil": "networkidle0",
"format": "Letter"
}' \
-o page.pdf</pre>
<h3>Response</h3>
<p><code>200 OK</code> — Returns <code>application/pdf</code>.</p>
<div class="status-codes">
<span class="status-ok">200</span> PDF generated
<span class="status-err">400</span> Missing or invalid URL
<span class="status-err">401</span> Invalid/missing API key
</div>
</div>
</section>
<section id="templates-list">
<h2>List Templates</h2>
<div class="endpoint">
<div class="endpoint-header">
<span class="method method-get">GET</span>
<span class="path">/v1/templates</span>
</div>
<p>List all available document templates with their field definitions.</p>
<h3>Example</h3>
<pre>curl https://docfast.dev/v1/templates \
-H "Authorization: Bearer YOUR_KEY"</pre>
<h3>Response</h3>
<pre>{
"templates": [
{
"id": "invoice",
"name": "Invoice",
"description": "Professional invoice with line items, taxes, and payment details",
"fields": [
{"name": "invoiceNumber", "type": "string", "required": true},
{"name": "date", "type": "string", "required": true},
{"name": "from", "type": "object", "required": true, "description": "Sender: {name, address?, email?, phone?, vatId?}"},
{"name": "to", "type": "object", "required": true, "description": "Recipient: {name, address?, email?, vatId?}"},
{"name": "items", "type": "array", "required": true, "description": "Line items: [{description, quantity, unitPrice, taxRate?}]"},
{"name": "currency", "type": "string", "required": false},
{"name": "notes", "type": "string", "required": false},
{"name": "paymentDetails", "type": "string", "required": false}
]
},
{
"id": "receipt",
"name": "Receipt",
"description": "Simple receipt for payments received",
"fields": [ ... ]
}
]
}</pre>
</div>
</section>
<section id="templates-render">
<h2>Render Template</h2>
<div class="endpoint">
<div class="endpoint-header">
<span class="method method-post">POST</span>
<span class="path">/v1/templates/:id/render</span>
</div>
<p>Render a template with your data and get a PDF. No HTML needed — just pass structured data.</p>
<h3>Path Parameters</h3>
<table>
<tr><th>Param</th><th>Description</th></tr>
<tr><td><code>:id</code></td><td>Template ID (<code>invoice</code> or <code>receipt</code>)</td></tr>
</table>
<h3>Request Body</h3>
<table>
<tr><th>Field</th><th>Type</th><th>Description</th></tr>
<tr><td><code>data</code> <span class="required">required</span></td><td>object</td><td>Template data (see field definitions from <code>/v1/templates</code>)</td></tr>
</table>
<h3>Invoice Example</h3>
<pre>curl -X POST https://docfast.dev/v1/templates/invoice/render \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{
"data": {
"invoiceNumber": "INV-2026-001",
"date": "2026-02-14",
"dueDate": "2026-03-14",
"from": {
"name": "Acme Corp",
"address": "123 Main St, Vienna",
"email": "billing@acme.com",
"vatId": "ATU12345678"
},
"to": {
"name": "Client Inc",
"address": "456 Oak Ave, Berlin",
"email": "accounts@client.com"
},
"items": [
{"description": "Web Development", "quantity": 40, "unitPrice": 95, "taxRate": 20},
{"description": "Hosting (monthly)", "quantity": 1, "unitPrice": 29}
],
"currency": "€",
"notes": "Payment due within 30 days.",
"paymentDetails": "IBAN: AT12 3456 7890 1234 5678"
}
}' \
-o invoice.pdf</pre>
<h3>Response</h3>
<p><code>200 OK</code> — Returns <code>application/pdf</code>.</p>
<div class="status-codes">
<span class="status-ok">200</span> PDF generated
<span class="status-err">400</span> Missing <code>data</code> field
<span class="status-err">404</span> Template not found
<span class="status-err">401</span> Invalid/missing API key
</div>
</div>
</section>
<section id="signup">
<h2>Sign Up (Get API Key)</h2>
<div class="endpoint">
<div class="endpoint-header">
<span class="method method-post">POST</span>
<span class="path">/v1/signup/free</span>
</div>
<p>Get a free API key instantly. No authentication required.</p>
<h3>Request Body</h3>
<table>
<tr><th>Field</th><th>Type</th><th>Description</th></tr>
<tr><td><code>email</code> <span class="required">required</span></td><td>string</td><td>Your email address</td></tr>
</table>
<h3>Example</h3>
<pre>curl -X POST https://docfast.dev/v1/signup/free \
-H "Content-Type: application/json" \
-d '{"email": "dev@example.com"}'</pre>
<h3>Response</h3>
<pre>{
"message": "Welcome to DocFast! 🚀",
"apiKey": "df_free_abc123...",
"tier": "free",
"limit": "100 PDFs/month",
"docs": "https://docfast.dev/#endpoints"
}</pre>
<div class="note warning">Save your API key securely. You can recover it via email at POST /v1/recover</div>
</div>
</section>
<section id="errors">
<h2>Error Handling</h2>
<p>All errors return JSON with an <code>error</code> field:</p>
<pre>{
"error": "Missing 'html' field"
}</pre>
<h3>Status Codes</h3>
<table>
<tr><th>Code</th><th>Meaning</th></tr>
<tr><td><code>200</code></td><td>Success — PDF returned as binary stream</td></tr>
<tr><td><code>400</code></td><td>Bad request — missing or invalid parameters</td></tr>
<tr><td><code>401</code></td><td>Unauthorized — missing or invalid API key</td></tr>
<tr><td><code>404</code></td><td>Not found — invalid endpoint or template ID</td></tr>
<tr><td><code>429</code></td><td>Rate limited — too many requests (100/min)</td></tr>
<tr><td><code>500</code></td><td>Server error — PDF generation failed</td></tr>
</table>
<h3>Common Mistakes</h3>
<pre><span class="comment"># ❌ Missing Authorization header</span>
curl -X POST https://docfast.dev/v1/convert/html \
-d '{"html": "test"}'
<span class="comment"># → {"error": "Missing API key. Use: Authorization: Bearer &lt;key&gt;"}</span>
<span class="comment"># ❌ Wrong Content-Type</span>
curl -X POST https://docfast.dev/v1/convert/html \
-H "Authorization: Bearer YOUR_KEY" \
-d '{"html": "test"}'
<span class="comment"># → Make sure to include -H "Content-Type: application/json"</span>
<span class="comment"># ✅ Correct request</span>
curl -X POST https://docfast.dev/v1/convert/html \
-H "Authorization: Bearer YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"html": "&lt;h1&gt;Hello&lt;/h1&gt;"}' \
-o output.pdf</pre>
</section>
<footer>
<p><a href="/">← Back to DocFast</a> &nbsp;|&nbsp; Questions? Email <a href="mailto:support@docfast.dev">support@docfast.dev</a></p>
</footer>
</div>
</body>
</html>