Developer quickstart

Web Scraping API Quickstart Guide

A practical path from your first API request to a reliable webpage extraction workflow, including rendering choices, response design, error handling, and production safeguards.

Software developer building a web scraping API workflow in a modern office
Photo by Mizuno K on Pexels.

A web scraping API turns a webpage into data your application can use without requiring you to maintain fetching, browser automation, parsing, content cleanup, and access-safety infrastructure. The fastest way to understand one is to send a real request, inspect the response, and then make deliberate choices about rendering and output fields.

This guide uses the ToolTrace Web Scraping API, but the planning principles apply to most website scraping API integrations. We will extract a public page, request clean Markdown and supporting context, verify how the page was fetched, and outline the controls that matter when a prototype becomes a production workflow.

What you need before using a web scraping API

You need a ToolTrace subscription on RapidAPI and an application key. The free Basic plan is suitable for learning the request format and testing a small workflow. Keep the key in an environment variable or secret manager. Never commit it to a repository, paste it into frontend JavaScript, or place it in a public screenshot.

You also need a publicly reachable HTTP or HTTPS URL. ToolTrace blocks private, local, and otherwise non-public destinations. This protection reduces the risk associated with server-side request forgery, a class of security issue described by OWASP's SSRF guidance. Use pages you are authorized to access and review the site's policies before automating collection. Our Acceptable Use Policy explains the standard expected from ToolTrace customers.

Start with one representative URL. Pick a page that resembles the content you ultimately need. A homepage often behaves differently from a product page, article, directory, or application screen.

Send your first web scraping API request

The primary extraction endpoint is POST /v1/extract. Copy your RapidAPI key into the first line, then run the complete command exactly as shown. Keep the key in an environment variable or secret manager and never commit it to source control.

export RAPIDAPI_KEY='paste_your_rapidapi_key_here'

curl --request POST \
  --url "https://tooltrace-web-scraping-api.p.rapidapi.com/v1/extract" \
  --header 'Content-Type: application/json' \
  --header "X-RapidAPI-Key: ${RAPIDAPI_KEY}" \
  --header 'X-RapidAPI-Host: tooltrace-web-scraping-api.p.rapidapi.com' \
  --data '{
    "url": "https://example.com",
    "render": "auto",
    "mode": "structured",
    "include": ["markdown", "metadata", "links"]
  }'

The request contains four decisions. url identifies the public webpage. render: auto tells ToolTrace to begin with a static fetch and use browser rendering only when evidence suggests it is necessary. mode: structured returns predictable named fields. The include array limits the response to Markdown, metadata, and links, which keeps the payload focused.

For the complete field definitions and generated examples, use the ToolTrace API documentation. The source specification is also available as an OpenAPI document for client generation and contract testing.

Read the extraction response before storing it

A successful response contains more than extracted content. The fetch object records the requested and final URLs, upstream status, content type, download size, elapsed time, redirect count, cache state, rendering method, and credits used. These values are useful operational evidence. Store the request identifier and relevant fetch fields alongside the content so that a surprising result can be investigated later.

{
  "fetch": {
    "final_url": "https://example.com/",
    "status_code": 200,
    "render_method": "static",
    "credits_used": 1
  },
  "mode": "structured",
  "markdown": "# Example Domain ...",
  "metadata": { "title": "Example Domain" },
  "links": []
}

The markdown field is a cleaned representation of the meaningful page content. It is often a better default than raw HTML for indexing, summarization, search, and language model prompts. Metadata and links add provenance and navigation context. The response can also include readable text, JSON-LD schema, page sections, and raw HTML when those outputs are explicitly requested.

Do not treat a 200 from the API as proof that the content is exactly what your application expects. Validate required fields, minimum useful text length, final domain, and content type. A webpage may return a valid access page, consent screen, or empty shell. ToolTrace reports access signals and warnings when available, but application-level validation still belongs in your workflow.

Choose static, automatic, or browser rendering

Rendering is the most important performance and cost decision in many web data extraction systems. ToolTrace supports three modes:

  • render: never uses fast static fetching and costs 1 credit for a successful processed request.
  • render: auto begins statically and invokes a browser only when the page appears to require it.
  • render: always uses browser rendering and costs 5 credits for a successful processed request.

Use static extraction for server-rendered articles, documentation, public listings, and pages whose important content is present in the initial HTML. Use a browser when content is assembled by JavaScript, revealed after client-side requests, or unavailable until a known selector appears. Automatic rendering is the sensible general default when your source set is mixed.

Browser requests can also specify wait_until, wait_for_selector, and a rendering timeout. domcontentloaded refers to the browser event documented by MDN's DOMContentLoaded reference. A selector wait should target a stable content element, not a decorative class likely to change during a redesign. For a deeper comparison, read Static vs Browser-Rendered Web Scraping.

Select outputs that match the job

A common early mistake is requesting every available field because it feels safer. Larger payloads cost bandwidth, increase storage, and create more downstream decisions. Start from the consumer of the data.

  • Markdown is effective for knowledge bases, semantic chunking, human review, and language model context.
  • Text suits simple search, classification, and word-level analysis.
  • Metadata provides title, description, canonical URL, language, author, publication date, favicon, Open Graph, and Twitter fields when available.
  • Links support discovery, internal graph analysis, and crawl planning.
  • Schema exposes JSON-LD and supported embedded structured data. The W3C JSON-LD specification explains the underlying format.
  • Sections preserve heading-based content organization for more meaningful chunks.
  • Raw HTML is useful when your own parser needs markup ToolTrace does not normalize.

ToolTrace also provides focused endpoints for metadata, links, schema, and SEO audits. Prefer a focused endpoint when the workflow requires only that result. It makes intent clearer and reduces unnecessary processing in your application.

Handle web scraping API errors deliberately

Production integrations should branch on status code and structured error code, not on message text. A 401 indicates missing or invalid authentication. A 403 covers blocked destinations or operations. A 413 means the request body is too large. A 422 identifies invalid request data or URL input. A 429 signals a plan quota, request rate, or concurrency limit. Upstream fetch failures and rendering timeouts are represented by 502 and 504, while 503 indicates a required service is temporarily unavailable.

Retry only failures that can reasonably be transient. Apply exponential backoff with jitter to temporary service and upstream errors. Honor rate-limit headers. Do not retry invalid URLs or blocked private destinations. Use an idempotency key when your surrounding workflow may submit the same operation more than once, and make your storage layer capable of recognizing duplicate results.

Move from quickstart to a production extraction workflow

A dependable pipeline separates request scheduling, extraction, validation, transformation, and storage. Queue URLs rather than processing an unbounded list inside one web request. Limit concurrency to your plan and infrastructure. Record the source URL, final URL, extraction time, rendering method, content hash, and schema version with every document.

Use content hashes to avoid unnecessary downstream work when a page has not materially changed. Define a freshness policy per source rather than refreshing every page at the same interval. Product prices may require frequent checks, while an evergreen guide may not. Observe latency, browser-render rate, credit use, error class, and useful-content rate. These measurements reveal both cost problems and source quality changes.

Finally, design for source drift. Websites change templates, navigation, access controls, and client-side behavior. Maintain a small set of representative URLs as fixtures and inspect them after meaningful configuration changes. If the extracted content feeds an AI system, preserve citations and read Web Scraping for AI Agents and RAG Pipelines before designing the indexing stage.

Ready to test a real page? Review ToolTrace plans, then open the ToolTrace RapidAPI listing.

Frequently asked questions

Is a web scraping API easier than maintaining a scraper?

For most product teams, yes. An API removes much of the work around fetching, browser infrastructure, content normalization, security controls, and operational scaling. Your team still owns source selection, lawful use, validation, storage, and product-specific transformations.

Should every request use browser rendering?

No. Static extraction is faster and uses fewer credits. Use automatic rendering for mixed sources or browser rendering for pages where JavaScript produces essential content.

What format is best for LLM and RAG use cases?

Clean Markdown with metadata and section structure is a strong default. It preserves readable hierarchy while avoiding much of the navigation and presentation noise found in raw HTML.