Idempotency

API Testing

// Definition

A property of an operation where calling it once and calling it many times produce the same effect. Critical for safe retries — GET, PUT, and DELETE are idempotent in HTTP semantics; POST is not. Tests should verify duplicate requests don't double-charge, double-create, or double-send.

// Code Example

CypressVerify duplicate requests don't double-create
TypeScript
it('PUT is idempotent — same payload twice yields one resource', () => {
  const body = { id: 'abc', name: 'Cypress' };

  cy.request('PUT', '/api/tools/abc', body).its('status').should('eq', 200);
  cy.request('PUT', '/api/tools/abc', body).its('status').should('eq', 200);

  cy.request('/api/tools').then((res) => {
    expect(res.body.filter((t: { id: string }) => t.id === 'abc')).to.have.length(1);
  });
});

// Related terms

Learn more · API Testing Masterclass

Chapter 4 · Lesson 4: Rate Limiting and Retry Strategies