feat: update examples page with SDK examples, fix API URLs
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 12m25s

- Node.js and Python examples now show SDK usage (recommended) + raw HTTP
- Fix api.docfast.dev → docfast.dev in all curl examples
- Update features subtitle to mention official SDKs
This commit is contained in:
DocFast Bot 2026-02-20 20:26:58 +00:00
parent 2e29d564ab
commit 0d66341f22
2 changed files with 57 additions and 47 deletions

View file

@ -163,7 +163,7 @@ footer .container { display: flex; justify-content: space-between; align-items:
<div class="code-block">
<span class="code-label">curl</span>
<pre><code>curl -X POST https://api.docfast.dev/v1/convert/html \
<pre><code>curl -X POST https://docfast.dev/v1/convert/html \
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="str">"Content-Type: application/json"</span> \
-d <span class="str">'{"html": "&lt;html&gt;...your invoice HTML...&lt;/html&gt;"}'</span> \
@ -178,7 +178,7 @@ footer .container { display: flex; justify-content: space-between; align-items:
<div class="code-block">
<span class="code-label">curl</span>
<pre><code>curl -X POST https://api.docfast.dev/v1/convert/markdown \
<pre><code>curl -X POST https://docfast.dev/v1/convert/markdown \
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="str">"Content-Type: application/json"</span> \
-d '{
@ -217,7 +217,7 @@ footer .container { display: flex; justify-content: space-between; align-items:
<div class="code-block">
<span class="code-label">curl</span>
<pre><code>curl -X POST https://api.docfast.dev/v1/convert/html \
<pre><code>curl -X POST https://docfast.dev/v1/convert/html \
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
-H <span class="str">"Content-Type: application/json"</span> \
-d @report.json \
@ -271,70 +271,80 @@ footer .container { display: flex; justify-content: space-between; align-items:
<!-- Node.js -->
<section id="nodejs" class="example-section">
<h2>Node.js Integration</h2>
<p>A complete Node.js script to generate a PDF and save it to disk. Works with Node 18+ using native fetch.</p>
<p>Install the official SDK: <code>npm install docfast</code></p>
<div class="code-block">
<span class="code-label">JavaScript — generate-pdf.mjs</span>
<pre><code><span class="kw">const</span> html = <span class="str">`
&lt;h1&gt;Hello from Node.js&lt;/h1&gt;
&lt;p&gt;Generated at ${</span><span class="kw">new</span> <span class="fn">Date</span>().<span class="fn">toISOString</span>()<span class="str">}&lt;/p&gt;
`</span>;
<span class="code-label">JavaScript — Using the SDK (recommended)</span>
<pre><code><span class="kw">import</span> DocFast <span class="kw">from</span> <span class="str">"docfast"</span>;
<span class="kw">import</span> { writeFileSync } <span class="kw">from</span> <span class="str">"fs"</span>;
<span class="kw">const</span> res = <span class="kw">await</span> <span class="fn">fetch</span>(<span class="str">"https://api.docfast.dev/v1/convert/html"</span>, {
<span class="kw">const</span> client = <span class="kw">new</span> <span class="fn">DocFast</span>(process.env.<span class="str">DOCFAST_API_KEY</span>);
<span class="cmt">// HTML to PDF</span>
<span class="kw">const</span> pdf = <span class="kw">await</span> client.<span class="fn">html</span>(<span class="str">"&lt;h1&gt;Hello World&lt;/h1&gt;"</span>);
<span class="fn">writeFileSync</span>(<span class="str">"output.pdf"</span>, pdf);
<span class="cmt">// Markdown to PDF</span>
<span class="kw">const</span> doc = <span class="kw">await</span> client.<span class="fn">markdown</span>(<span class="str">"# Report\n\nQ4 revenue grew **32%**."</span>);
<span class="cmt">// With options</span>
<span class="kw">const</span> report = <span class="kw">await</span> client.<span class="fn">html</span>(html, {
format: <span class="str">"A4"</span>,
landscape: <span class="kw">true</span>,
margin: { top: <span class="str">"20mm"</span>, bottom: <span class="str">"20mm"</span> },
});</code></pre>
</div>
<div class="code-block" style="margin-top: 16px;">
<span class="code-label">JavaScript — Using fetch (no dependencies)</span>
<pre><code><span class="kw">const</span> res = <span class="kw">await</span> <span class="fn">fetch</span>(<span class="str">"https://docfast.dev/v1/convert/html"</span>, {
method: <span class="str">"POST"</span>,
headers: {
<span class="str">"Authorization"</span>: <span class="str">`Bearer ${process.env.DOCFAST_API_KEY}`</span>,
<span class="str">"Content-Type"</span>: <span class="str">"application/json"</span>,
},
body: <span class="fn">JSON.stringify</span>({ html }),
body: <span class="fn">JSON.stringify</span>({ html: <span class="str">"&lt;h1&gt;Hello&lt;/h1&gt;"</span> }),
});
<span class="kw">if</span> (!res.ok) <span class="kw">throw new</span> <span class="fn">Error</span>(<span class="str">`API error: ${res.status}`</span>);
<span class="kw">const</span> buffer = Buffer.<span class="fn">from</span>(<span class="kw">await</span> res.<span class="fn">arrayBuffer</span>());
<span class="kw">await</span> <span class="kw">import</span>(<span class="str">"fs"</span>).then(<span class="fn">fs</span> =&gt;
fs.<span class="fn">writeFileSync</span>(<span class="str">"output.pdf"</span>, buffer)
);
console.<span class="fn">log</span>(<span class="str">"✓ Saved output.pdf"</span>);</code></pre>
<span class="kw">const</span> pdf = Buffer.<span class="fn">from</span>(<span class="kw">await</span> res.<span class="fn">arrayBuffer</span>());</code></pre>
</div>
</section>
<!-- Python -->
<section id="python" class="example-section">
<h2>Python Integration</h2>
<p>Generate a PDF from Python using the <code>requests</code> library. Drop this into any Flask, Django, or FastAPI app.</p>
<p>Install the official SDK: <code>pip install docfast</code></p>
<div class="code-block">
<span class="code-label">Python — generate_pdf.py</span>
<pre><code><span class="kw">import</span> os
<span class="kw">import</span> requests
<span class="code-label">Python — Using the SDK (recommended)</span>
<pre><code><span class="kw">from</span> docfast <span class="kw">import</span> DocFast
html = <span class="str">"""
&lt;h1&gt;Hello from Python&lt;/h1&gt;
&lt;p&gt;This PDF was generated via the DocFast API.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Fast rendering&lt;/li&gt;
&lt;li&gt;Pixel-perfect output&lt;/li&gt;
&lt;li&gt;Simple REST API&lt;/li&gt;
&lt;/ul&gt;
"""</span>
client = <span class="fn">DocFast</span>(<span class="str">"df_pro_your_api_key"</span>)
<span class="cmt"># HTML to PDF</span>
pdf = client.<span class="fn">html</span>(<span class="str">"&lt;h1&gt;Hello World&lt;/h1&gt;"</span>)
<span class="kw">with</span> <span class="fn">open</span>(<span class="str">"output.pdf"</span>, <span class="str">"wb"</span>) <span class="kw">as</span> f:
f.<span class="fn">write</span>(pdf)
<span class="cmt"># With options</span>
pdf = client.<span class="fn">html</span>(html, format=<span class="str">"A4"</span>, landscape=<span class="kw">True</span>)
<span class="cmt"># Async support</span>
<span class="kw">from</span> docfast <span class="kw">import</span> AsyncDocFast
<span class="kw">async with</span> <span class="fn">AsyncDocFast</span>(<span class="str">"df_pro_your_api_key"</span>) <span class="kw">as</span> client:
pdf = <span class="kw">await</span> client.<span class="fn">html</span>(<span class="str">"&lt;h1&gt;Hello&lt;/h1&gt;"</span>)</code></pre>
</div>
<div class="code-block" style="margin-top: 16px;">
<span class="code-label">Python — Using requests (no SDK)</span>
<pre><code><span class="kw">import</span> requests
response = requests.<span class="fn">post</span>(
<span class="str">"https://api.docfast.dev/v1/convert/html"</span>,
headers={
<span class="str">"Authorization"</span>: <span class="str">f"Bearer {</span>os.environ[<span class="str">'DOCFAST_API_KEY'</span>]<span class="str">}"</span>,
<span class="str">"Content-Type"</span>: <span class="str">"application/json"</span>,
},
json={<span class="str">"html"</span>: html},
<span class="str">"https://docfast.dev/v1/convert/html"</span>,
headers={<span class="str">"Authorization"</span>: <span class="str">f"Bearer {api_key}"</span>},
json={<span class="str">"html"</span>: <span class="str">"&lt;h1&gt;Hello&lt;/h1&gt;"</span>},
)
response.<span class="fn">raise_for_status</span>()
<span class="kw">with</span> <span class="fn">open</span>(<span class="str">"output.pdf"</span>, <span class="str">"wb"</span>) <span class="kw">as</span> f:
f.<span class="fn">write</span>(response.content)
<span class="fn">print</span>(<span class="str">"✓ Saved output.pdf"</span>)</code></pre>
pdf = response.content</code></pre>
</div>
</section>

View file

@ -402,7 +402,7 @@ html, body {
<section class="features" id="features">
<div class="container">
<h2 class="section-title">Everything you need</h2>
<p class="section-sub">A complete PDF generation API. No SDKs, no dependencies, no setup.</p>
<p class="section-sub">A complete PDF generation API. Official SDKs for Node.js &amp; Python, or just use curl.</p>
<div class="features-grid">
<div class="feature-card">
<div class="feature-icon" aria-hidden="true"></div>