Skip to content

myastroapp/snapapi-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

snapapi

Node.js client for SnapAPI — capture screenshots, extract metadata, generate PDFs, and pull text from any URL.

Zero dependencies. Uses native fetch (Node 18+).

Live Demo · API Docs · OpenAPI Spec · Free Website Audit

Install

npm install snapapi

Quick Start

const { SnapAPI } = require('snapapi');

const snap = new SnapAPI('snap_your_api_key');

// Take a screenshot
const { buffer } = await snap.screenshot('https://github.com');
fs.writeFileSync('github.png', buffer);

// Extract metadata (OG tags, Twitter cards, etc.)
const { data } = await snap.metadata('https://github.com');
console.log(data.title, data.og, data.twitter);

// Generate a PDF
const pdf = await snap.pdf('https://example.com', { format: 'Letter' });
fs.writeFileSync('page.pdf', pdf.buffer);

// Extract text
const text = await snap.text('https://example.com');
console.log(text.data.text, text.data.word_count);

// Check usage
const usage = await snap.usage();
console.log(`${usage.used}/${usage.limit} requests used this month`);

Getting an API Key

Sign up at snap.michaelcli.com or use the client directly:

const { SnapAPI } = require('snapapi');

const { key } = await SnapAPI.signup('you@example.com', 'Your Name');
console.log(key); // snap_...

Free tier includes 50 requests/month.

API Reference

new SnapAPI(apiKey, options?)

Parameter Type Description
apiKey string Your API key (starts with snap_)
options.baseUrl string Override the API URL (default: https://snap.michaelcli.com)

snap.screenshot(url, opts?)

Capture a PNG or JPEG screenshot of any webpage.

Option Type Default Description
width number 1280 Viewport width (320--3840)
height number 720 Viewport height (240--2160)
full_page boolean false Capture full scrollable page
format 'png' | 'jpeg' 'png' Image format

Returns { buffer: Buffer, contentType: string, usage: { used, limit } }


snap.metadata(url)

Extract Open Graph tags, Twitter Cards, meta tags, and favicon from a URL.

Returns:

{
  data: {
    url, title, description, favicon,
    og: { title, description, image, ... },
    twitter: { card, title, description, ... },
    meta_tags: [{ name, content }, ...]
  },
  usage: { used, limit }
}

snap.pdf(url, opts?)

Generate a PDF from any webpage.

Option Type Default Description
format 'A4' | 'Letter' | 'Legal' | 'A3' 'A4' Page size
landscape boolean false Landscape orientation

Returns { buffer: Buffer, contentType: string, usage: { used, limit } }


snap.text(url)

Extract clean, readable text content from a webpage.

Returns:

{
  data: { url, title, text, word_count },
  usage: { used, limit }
}

snap.usage()

Get current month's usage statistics.

Returns { tier, used, limit, remaining }


SnapAPI.signup(email, name, options?)

Static method. Creates a free API key -- no authentication required.

Returns { key, name, tier, message }

Error Handling

All methods throw SnapAPIError on non-2xx responses:

const { SnapAPI, SnapAPIError } = require('snapapi');

try {
  await snap.screenshot('https://example.com');
} catch (err) {
  if (err instanceof SnapAPIError) {
    console.error(err.status);  // HTTP status code
    console.error(err.message); // Error message from API
    console.error(err.detail);  // Additional detail (if any)
  }
}
Status Meaning
400 Invalid request (bad URL, invalid parameters)
401 Missing or invalid API key
429 Monthly rate limit exceeded
500 Server-side failure

License

MIT

About

Node.js client for SnapAPI — website screenshots, metadata extraction, PDF generation. Free tier: 50 req/mo, paid from $2.50/mo (launch special).

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors