{"data":{"id":189,"slug":"rate-limit-headers-explained-part-10-189","title":"Rate limit headers explained, part 10","excerpt":"For part 10, we revisit the basics with a fresh example and a few lessons learned the hard way. A well-behaved API tells you how many requests you have left before it starts saying no. Reading those…","seriesName":"Rate limit headers explained","seriesPart":10,"sections":[{"heading":"Introduction","paragraphs":["For part 10, we revisit the basics with a fresh example and a few lessons learned the hard way. A well-behaved API tells you how many requests you have left before it starts saying no. Reading those headers turns rate limiting from a surprise into a plan."]},{"heading":"Common pitfalls","paragraphs":["Always identify your client honestly with a descriptive User-Agent, and keep your request rate modest. A crawler that behaves like a considerate visitor is far less likely to cause problems for the site operator.","Read the site's terms of service before you start. Many sites welcome automated access within limits and say so explicitly; others ask you to use an API instead."]},{"heading":"Putting it into practice","paragraphs":["Pagination comes in several shapes: numbered pages, next links, offsets and opaque cursors. Each has trade-offs, and a robust scraper should detect the end of the result set rather than assuming a fixed number of pages.","Write small, focused tests for your parsers using saved HTML fixtures. They run in milliseconds and catch layout changes long before a full crawl would."]},{"heading":"Key takeaway","paragraphs":["Track X-RateLimit-Remaining, slow down as it approaches zero, and when you receive a 429, wait for the number of seconds in Retry-After before trying again."]}],"authorId":11,"authorName":"Oliver Kim","authorSlug":"oliver-kim","category":"APIs","tags":["http","ethics","playwright","javascript"],"publishedAt":"2024-08-21T00:00:00.000Z","wordCount":195,"readingTimeMinutes":2}}