TestingAPIs is still being built. If something breaks, email support@testingapis.com.

Tutorial

Learn API resilience

Every API call can fail: the server is slow, overloaded or restarting, the connection drops, or you've sent too many requests. A resilient client handles all of it. It waits a sensible time, retries what is safe to retry, backs off when asked, never charges a customer twice, and stops calling a service that is clearly down.

These lessons explain each of those ideas from the start, then build them in plain JavaScript with no libraries. Every failure in them is real: the API at https://api.testingapis.comhas endpoints that fail on purpose, and every output shown is what the code printed when it ran against them. You'll need to know some JavaScript, including async, await and fetch. If HTTP status codes are new to you, start with the API testing tutorial. Some endpoints need a free account; set your key in TESTINGAPIS_KEY and the example project sends it with every request.

Download the example project

resilience-examples.zipOne file per lesson, 33 tests and the demo scripts. Node.js 22 or later, no dependencies. Unzip and run npm test.

8 lessons3 levelsFree

Words you'll meet

15 terms

Each one is explained properly in its lesson. This list is for looking one up later.

TermMeaningExplained in
Transient failureA failure that goes away by itself, such as an overloaded server or a dropped connectionLesson 1
Permanent failureA failure that repeats until the request changes, such as a 404 or a missing fieldLesson 1
TimeoutThe longest a client will wait for a response before treating the request as failedLesson 2
Percentile (p99)The time that 99 out of 100 requests beat; the basis for choosing a timeoutLesson 2
RetrySending the same request again after a failureLesson 3
IdempotentSafe to repeat: doing it twice has the same effect on the server as doing it onceLesson 3
BackoffThe pause before a retry, usually growing after each failureLesson 4
JitterRandomness added to the pause, so many clients don't retry at the same momentLesson 4
Thundering herdMany clients retrying in step, hitting a recovering server in wavesLesson 4
Rate limitA cap on how many requests a client may send in a period; going over gets a 429Lesson 5
Retry-AfterA response header saying how long to wait before trying againLesson 5
Idempotency keyA unique value sent with a request so the server can recognize a repeat and not act twiceLesson 6
Circuit breakerA switch that stops calls to a failing service for a while, so they fail fastLesson 7
FallbackWhat a client does instead when a call fails, such as showing cached dataLesson 7
Fault injectionCausing failures on purpose, to test how code handles themLesson 8