api-design

  • PSR-18 middleware, and the order that matters

    Four decorators around an HTTP client, composed in an order that is obvious once and unrecoverable afterwards. Signing inside retry is mandatory — a retried request needs a…

  • A contract fixture published by a consumer

    Tests describing what a consumer reads, written by them, run by us. Owning the tests ourselves means asserting what we intended, and the risk is the gap between…

  • json_encode with JSON_THROW_ON_ERROR, everywhere, finally

    A codebase-wide sweep for json_encode and json_decode without the throw flag, eleven years after the flag arrived. Twenty-two silent failures is the finding, and one of them had…

  • An idempotency key that a consumer reused for a different body

    A documented idempotency contract, and the first consumer to exercise the conflict case. The conflict response is the part of an idempotency contract that has to be specified,…

  • The anti-corruption layer that needed a second mapper

    One supplier, two API versions running simultaneously during their own migration, and a translation layer built for one shape. The layer had assumed one upstream shape at a…

  • A type generated from a schema, and the assertion I removed

    Types generated from an OpenAPI document, and a response validated at runtime rather than asserted at compile time. A generated type describes the specification and the specification is…

  • An enum with a from() that had to become tryFrom()

    A backed enum hydrated from a database column, and a row written in 2019 with a value the enum does not have. from() throwing is correct behaviour and…

  • Percentiles labelled by consumer, and the outlier

    One label on a histogram, and a p95 that had been describing nobody. An aggregate percentile is a weighted average of populations that may have nothing in common,…

  • The PSR-18 client I wrote for one API

    A supplier API with a signing scheme, a rate limit and a pagination style of its own, and the same four concerns implemented in three places.

  • The endpoint that was slow for one customer

    A healthy p95 and one customer for whom the endpoint takes four seconds. An aggregate metric that averages away the only case that matters.