An API is a defined set of rules that lets one piece of software communicate with another, allowing applications to request and exchange data in a structured format, such as JSON, without needing to parse raw HTML. When a site loads its data from an API, Scrapy's documentation calls reproducing those requests the preferred approach, since it gives structured, complete data with minimum parsing time.

On the web, "API" usually means a web API: a set of URLs, called endpoints, that accept HTTP requests and return data instead of pages.

How an API Request Works

  1. The client calls an endpoint: it sends an HTTP request, such as GET, to a specific URL.
  2. It follows the API's schema: the request must use the parameters and format the API expects, or the server can't return a usable answer.
  3. It proves who it is: many APIs require an API key or an access token from OAuth.
  4. The server responds: it returns data, often JSON, plus a status code such as 200 for success or 429 when too many requests were sent.

Common Types of APIs

  • REST: an architectural style for web services. Cloudflare notes that most APIs today are REST APIs.
  • SOAP: a messaging protocol, rather than a style like REST.
  • GraphQL: a query language for APIs. Its official site says clients can request exactly the fields they need and get related data in a single request.
  • Webhooks: the server calls your URL when an event happens, instead of you asking. See webhook.

API vs. Web Scraping

Official APIWeb scraping
What you getStructured data, often JSONHTML built for people
LimitsDocumented, such as GitHub's 60 unauthenticated or 5,000 authenticated requests per hourNot published, though sites can still rate-limit
FormatSet by the API's schemaWhatever the page's HTML happens to be
CoverageOnly the data the owner chooses to exposeAnything shown on public pages

Some proxy and data-extraction providers offer their own "scraper APIs" that combine proxy infrastructure with built-in parsing, effectively turning an unstructured website into a structured API response on the customer's behalf.

Many Sites Have a Hidden API

Pages that load content with JavaScript often fetch it from the site's own API. Scrapy's documentation recommends finding that request in your browser's network tool and reproducing it. Sometimes the same HTTP method and URL are enough. Other times you also need its headers, body or form parameters. If the response is JSON, you can load it directly instead of parsing HTML.

Retry Only Requests That Are Safe to Repeat

HTTP methods differ in what happens if a request is sent twice. MDN defines a method as idempotent when several identical requests have the same intended effect as one:

  • Safe to repeat: GET, HEAD, OPTIONS, PUT and DELETE are idempotent.
  • Not guaranteed: POST and PATCH are not, so retrying a failed POST can create a duplicate order, message or record.
  • A fix in progress: an IETF draft defines an Idempotency-Key header that lets servers recognize retries of the same POST. It lists Stripe, Adyen and others as already using a similar header.

What It Means for Web Scraping

  • Check for an API first: an official or hidden API usually gives cleaner data than HTML.
  • Respect the documented limits: GitHub's higher limit applies to an authenticated user, so it follows the account, not the IP.
  • Retry reads, not writes: automatic retries are safest on GET requests.