feat: add URL-to-PDF examples to examples page
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Has been cancelled
- Add 'URL to PDF' nav link and example section - Show basic and advanced cURL examples for /v1/convert/url - Include security notes (JS disabled, private URLs blocked) - Add test coverage for the new section
This commit is contained in:
parent
503e65103e
commit
c233f289c9
3 changed files with 97 additions and 0 deletions
|
|
@ -111,6 +111,7 @@ footer .container { display: flex; justify-content: space-between; align-items:
|
|||
<a href="#markdown">Markdown</a>
|
||||
<a href="#charts">Charts</a>
|
||||
<a href="#receipt">Receipt</a>
|
||||
<a href="#url-to-pdf">URL to PDF</a>
|
||||
<a href="#nodejs">Node.js</a>
|
||||
<a href="#python">Python</a>
|
||||
<a href="#go">Go</a>
|
||||
|
|
@ -270,6 +271,36 @@ footer .container { display: flex; justify-content: space-between; align-items:
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<!-- URL to PDF -->
|
||||
<section id="url-to-pdf" class="example-section">
|
||||
<h2>URL to PDF</h2>
|
||||
<p>Capture a live webpage and convert it to PDF. Send a URL to the <code>/v1/convert/url</code> endpoint and get a rendered PDF back. JavaScript is disabled for security (SSRF protection), and private/internal URLs are blocked.</p>
|
||||
|
||||
<div class="code-block">
|
||||
<span class="code-label">curl — basic</span>
|
||||
<pre><code>curl -X POST https://docfast.dev/v1/convert/url \
|
||||
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
|
||||
-H <span class="str">"Content-Type: application/json"</span> \
|
||||
-d <span class="str">'{"url": "https://example.com"}'</span> \
|
||||
--output page.pdf</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="code-block">
|
||||
<span class="code-label">curl — with options</span>
|
||||
<pre><code>curl -X POST https://docfast.dev/v1/convert/url \
|
||||
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
|
||||
-H <span class="str">"Content-Type: application/json"</span> \
|
||||
-d <span class="str">'{
|
||||
"url": "https://example.com",
|
||||
"format": "A4",
|
||||
"margin": { "top": "20mm", "bottom": "20mm" },
|
||||
"scale": 0.8,
|
||||
"printBackground": true
|
||||
}'</span> \
|
||||
--output page.pdf</code></pre>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Node.js -->
|
||||
<section id="nodejs" class="example-section">
|
||||
<h2>Node.js Integration</h2>
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
<a href="#markdown">Markdown</a>
|
||||
<a href="#charts">Charts</a>
|
||||
<a href="#receipt">Receipt</a>
|
||||
<a href="#url-to-pdf">URL to PDF</a>
|
||||
<a href="#nodejs">Node.js</a>
|
||||
<a href="#python">Python</a>
|
||||
<a href="#go">Go</a>
|
||||
|
|
@ -219,6 +220,36 @@
|
|||
</div>
|
||||
</section>
|
||||
|
||||
<!-- URL to PDF -->
|
||||
<section id="url-to-pdf" class="example-section">
|
||||
<h2>URL to PDF</h2>
|
||||
<p>Capture a live webpage and convert it to PDF. Send a URL to the <code>/v1/convert/url</code> endpoint and get a rendered PDF back. JavaScript is disabled for security (SSRF protection), and private/internal URLs are blocked.</p>
|
||||
|
||||
<div class="code-block">
|
||||
<span class="code-label">curl — basic</span>
|
||||
<pre><code>curl -X POST https://docfast.dev/v1/convert/url \
|
||||
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
|
||||
-H <span class="str">"Content-Type: application/json"</span> \
|
||||
-d <span class="str">'{"url": "https://example.com"}'</span> \
|
||||
--output page.pdf</code></pre>
|
||||
</div>
|
||||
|
||||
<div class="code-block">
|
||||
<span class="code-label">curl — with options</span>
|
||||
<pre><code>curl -X POST https://docfast.dev/v1/convert/url \
|
||||
-H <span class="str">"Authorization: Bearer YOUR_API_KEY"</span> \
|
||||
-H <span class="str">"Content-Type: application/json"</span> \
|
||||
-d <span class="str">'{
|
||||
"url": "https://example.com",
|
||||
"format": "A4",
|
||||
"margin": { "top": "20mm", "bottom": "20mm" },
|
||||
"scale": 0.8,
|
||||
"printBackground": true
|
||||
}'</span> \
|
||||
--output page.pdf</code></pre>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Node.js -->
|
||||
<section id="nodejs" class="example-section">
|
||||
<h2>Node.js Integration</h2>
|
||||
|
|
|
|||
35
src/__tests__/examples-url-to-pdf.test.ts
Normal file
35
src/__tests__/examples-url-to-pdf.test.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { describe, it, expect } from 'vitest';
|
||||
import { readFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
|
||||
describe('examples.html - URL to PDF section', () => {
|
||||
const html = readFileSync(join(__dirname, '../../public/examples.html'), 'utf-8');
|
||||
|
||||
it('contains a URL to PDF section', () => {
|
||||
expect(html).toContain('id="url-to-pdf"');
|
||||
expect(html).toContain('URL to PDF');
|
||||
});
|
||||
|
||||
it('contains a nav link to the URL to PDF section', () => {
|
||||
expect(html).toContain('href="#url-to-pdf"');
|
||||
});
|
||||
|
||||
it('uses the correct API URL (docfast.dev, not api.docfast.dev)', () => {
|
||||
expect(html).toContain('https://docfast.dev/v1/convert/url');
|
||||
expect(html).not.toContain('api.docfast.dev');
|
||||
});
|
||||
|
||||
it('shows the /v1/convert/url endpoint', () => {
|
||||
expect(html).toContain('/v1/convert/url');
|
||||
});
|
||||
|
||||
it('does NOT reference non-existent SDKs for URL conversion', () => {
|
||||
expect(html).not.toContain('docfast-url');
|
||||
expect(html).not.toContain('url-to-pdf-sdk');
|
||||
});
|
||||
|
||||
it('mentions security notes about JavaScript and private URLs', () => {
|
||||
expect(html).toMatch(/[Jj]ava[Ss]cript.*disabled|disabled.*[Jj]ava[Ss]cript/i);
|
||||
expect(html).toMatch(/private|internal/i);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue