Rate Limiting

API Testingintermediate

// Definition

An API protection mechanism that caps how many requests a client can make in a window. Tests should verify both the limit threshold and the response when exceeded (typically HTTP 429 with Retry-After).

// Why it matters

Rate limiting caps how many requests a client can make in a window, blunting brute-force, scraping, and accidental hammering. QA verifies two things people forget: that the limit actually triggers (returns 429), and that it resets correctly — a limiter that never releases is its own outage.

// How to test

// Fire past the documented limit; expect a 429 with Retry-After
const attempts = Array.from({ length: 12 }) // limit is 10/min
cy.wrap(attempts).each(() =>
  cy.request({ url: '/api/login', method: 'POST', body: creds, failOnStatusCode: false })
)
cy.request({ url: '/api/login', method: 'POST', body: creds, failOnStatusCode: false })
  .then((res) => {
    expect(res.status).to.eq(429)
    expect(res.headers).to.have.property('retry-after')
  })

// Common mistakes

  • Limiting by IP only (defeated by proxies) or by account only (defeated by spraying)
  • No Retry-After header, so well-behaved clients can't back off
  • Counting failed and successful requests the same way, locking out legit users

// Related terms

Learn more · API Testing Masterclass

Chapter 4 · Lesson 4: Rate Limiting and Retry Strategies