Ramblings of Shadowhand

Errata - an API Problem document and middleware package

Today, I released Errata, a package for the RFC 9457 API Problem specification.

errata-banner

While there are several other packages that support this specification, most of them are outdated and using legacy PHP style instead of modern features. Errata requires PHP 8.4 for property hooks. By using property hooks, we can avoid dealing with getters and setters and just use properties, but with safety checks.

Errata also maps out all the standard 4xx and 5xx HTTP status codes as discrete objects, so you can do this:

use Errata\Http\Client\PaymentRequired;

$problem = new PaymentRequired(
    details: 'Your account balance of $3.50 is not enough to complete this purchase.',
);

It also includes a PSR-15 middleware to catch exceptions throwables, convert them into problems, and return application/problem+json responses.

#api-problem #exception-handler #json-api #psr-15 #psr-7 #rfc-9457