Non-FictionInformativeEducational

API Design and Integration eBook

A Coursebook on API Design and Integration

by Finley Erich

  • English
  • 152 pages
  • 2026
  • SamEnrico

A Coursebook on API Design and Integration

Formats

Free sample

Chapter 1: The Contract Fallacy--It was 3:47 AM in Austin, Texas, and the phone wouldn't stop buzzing. Sarah, the senior platform engineer on call, fumbled for her phone, already knowing what she would find. The API error rates had spiked from 0.2% to 14.7%. The company processed $50 million in payments daily. Simple math told her that every minute of downtime cost roughly $35,000.She logged into the dashboard and saw the culprit: a 500 Internal Server Error cascade coming from the customer profile endpoint.

The endpoint had worked perfectly for eighteen months. Nothing had changed in the last deployment—a routine security patch that had passed all tests. The database migration had run successfully. The unit tests passed. The integration tests passed.

The staging environment showed no issues.Yet production was on fire.Sarah spent the next forty-five minutes tracing the problem. The security patch had included an update to an ORM library. The new version of the library, when encountering a null value in a database column that was marked as required in the model definition, threw an exception instead of returning null. The column in question? middle_name.

Thousands of customer records had null middle names. The API, which had been returning "middle_name": null for years, now crashed on those records.The code change was correct. The library update was reasonable. The database schema was fine. And yet, the API had broken because of a promise that no one knew they had made: the implicit promise that middle_name could be null.The engineering team spent the next week discussing whose fault it was.

The DBA blamed the ORM update. The security team blamed the DBA for not flagging the null column. The product team blamed engineering for "not testing properly." The customers blamed everyone.No one asked the question that mattered: What contract had the API implicitly agreed to, and how could that contract be made explicit before it broke?The Invisible Promises Every API makes promises. Some of them are written in documentation. Some are encoded in Open API specifications.

Some exist only in the minds of the developers who built the API and the developers who consume it. The gap between these promises—the documented, the encoded, and the assumed—is where catastrophic failures live.Let me give you another example, one that cost a healthcare startup its entire customer base. The API had an endpoint called GET /patients/{id}/insurance. The documentation stated that the response contained a field called policy_status with possible values of active, pending, or expired. What the documentation did not say was that the field could also return null if the patient had no insurance on file.

The mobile app developers, reading the documentation, assumed policy_status would always be one of the three strings. They did not write code to handle null. When the first patient with no insurance used the app, the app crashed. The patient, already stressed about their medical bills, could not check their coverage. They switched to a competitor.

The startup lost seventeen such patients in one week before they understood the problem.The developers had not violated the documentation. The documentation was simply incomplete. But the API had made a promise—"you will always get a string in policy_status"—that the developers had assumed and the documentation had failed to capture.This is what I call the Contract Fallacy: the belief that your API's contract is what you say it is, rather than what your consumers believe it to be.The truth is more brutal. Your API's contract is the intersection of everything you have ever returned, every status code you have ever sent, every header you have ever included, and every behavior your consumers have come to rely upon. If you ever returned "policy_status": null even once, and a consumer wrote code that expected a string, you have made a promise.

You cannot un-make it simply by updating your documentation to say "null is possible." The damage is already in production, running on some phone, waiting to crash.The Three Layers of Contract To understand how APIs break, we need to understand the three distinct layers of contractual obligation that every API creates.Layer 1: The Explicit Contract The explicit contract is what you write down. It includes your Open API specification, your documentation, your example responses, and your changelog. This is the contract you intend to uphold. It is the easiest layer to manage because you control it completely. You can change it, version it, and communicate changes through official channels.The problem with the explicit contract is not that it is hard to write.

The problem is that most developers never read it. Or they read it once, six months ago, and have forgotten the details. Or they read it but misunderstood because your error response documentation was buried on page forty-seven of a PDF.When I surveyed API consumers at a Fortune 500 company, I found that only 23% had read the complete API documentation. The rest had read the "Getting Started" guide, looked at examples, and started coding. They assumed that the examples represented the complete contract.

When those examples did not show null values, the developers assumed null values never appeared.Layer 2: The Behavioral Contract The behavioral contract is what your API actually does, regardless of what your documentation says. This includes the specific status codes you return, the exact format of dates and timestamps, the behavior of your rate limiter when exceeded, and the content of your error messages.Behavioral contracts are insidious because they form through repetition. If you return 429 Too Many Requests with a Retry-After header that is a float (e.g., 1.5) for three months, then change it to an integer (e.g., 2), you have broken the behavioral contract even if your documentation never specified the type. Some client's JSON parser will fail. Some developer will have written Math.ceil(retry After) assuming a float, and their code will continue to work with the float but break with the integer.The only way to manage behavioral contracts is to treat your API's observable behavior as sacrosanct.

Every response you send is a test case. Every error code you return is a commitment. If you want to change behavior, you must either version your API or accept that some clients will break.Layer 3: The Assumptive Contract The assumptive contract is the most dangerous and the least discussed. It is composed of everything your consumers assume about your API without ever checking. These assumptions come from experience with other APIs, from intuition, or from a reasonable reading of incomplete documentation.Common assumptions include:"Field order in JSON responses will be stable." (It is not guaranteed by the JSON specification, but many clients depend on it.)"The API will never return a 201 Created without a Location header." (It might, and the client will crash.)"If I send the same request twice, I will get the same response." (Idempotency is not automatic for POST requests.)"An empty array and a null value are the same thing." (They are not, but clients often treat them as interchangeable until they break.)Assumptive contracts cannot be documented away.

You cannot write "by the way, JSON object keys are not ordered" and expect every Java Script developer to change…

This is the end of the free sample. Get the eBook to keep going. Buy now

About this book

A Coursebook on API Design and Integration

Details

Author
Finley Erich
Publisher
SamEnrico
Language
English
Genre
Non-Fiction, Informative, Educational
Released
2026-06-02
Pages (approx.)
152
Available as
eBook, Audiobook

Read better in the ZLOADR app

Your eBooks on your phone or tablet. Sign in with your SamEnrico account and start reading.

More by Finley Erich

See all

You may also like

See all