<?xml version="1.0" encoding="UTF-8"?>
<response><data><post><id>29</id><slug>rate-limit-headers-explained-part-2-29</slug><title>Rate limit headers explained, part 2</title><excerpt>For part 2, 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…</excerpt><seriesName>Rate limit headers explained</seriesName><seriesPart>2</seriesPart><sections><item><heading>Introduction</heading><paragraphs><item>For part 2, 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.</item></paragraphs></item><item><heading>What to watch for</heading><paragraphs><item>Log every request with its URL, status code and duration. When something goes wrong at two in the morning, those logs are the difference between a quick fix and a long investigation.</item><item>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.</item></paragraphs></item><item><heading>Going further</heading><paragraphs><item>Keep configuration such as base URLs, delays and selectors out of your code. Changing a delay should not require a redeploy.</item><item>Character encodings still cause trouble. Decode responses using the charset the server declares, and normalise text before comparing or storing it.</item></paragraphs></item><item><heading>Key takeaway</heading><paragraphs><item>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.</item></paragraphs></item></sections><authorId>10</authorId><authorName>Aisha Rossi</authorName><authorSlug>aisha-rossi</authorSlug><category>APIs</category><tags><item>python</item><item>playwright</item></tags><publishedAt>2024-04-28T00:00:00.000Z</publishedAt><wordCount>171</wordCount><readingTimeMinutes>2</readingTimeMinutes></post></data></response>
