Download the PHP package crell/api-problem without Composer
On this page you can find all versions of the php package crell/api-problem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crell/api-problem
More information about crell/api-problem
Files in crell/api-problem
Package api-problem
Short Description PHP wrapper for the api-problem IETF specification
License MIT
Homepage https://github.com/Crell/ApiProblem
Informations about the package api-problem
ApiProblem
This library provides a simple and straightforward implementation of the IETF Problem Details for HTTP APIs, RFC 9457.
RFC 9457 is a simple specification for formatting error responses from RESTful APIs on the web. This library provides a simple and convenient way to interact with that specification. It supports generating and parsing RFC 9457 messages, in both JSON and XML variants.
Generating responses
What's that you say? Someone sent your API a bad request? Tell them it's a problem!
Or, even better, you can subclass ApiProblem for a specific problem type (since the type and title are supposed to go together and be relatively fixed), then just populate your own error-specific data. Just like extending an exception!
If you're using a library or framework that wants to do its own JSON serialization, that's also fully supported. ApiProblem implements\JsonSerializable
, so you can pass it directly to json_encode()
as if it were a naked array.
Sending Responses
You're probably using PSR-7 for your responses. That's why this library includes a utility to convert your ApiProblem
object to a PSR-7 ResponseInterface
object, using a PSR-17 factory of your choice. Like so:
That gives back a fully-functional and marked Response object, ready to send back to the client.
Receiving responses
Are you sending messages to an API that is responding with API-Problem errors? No problem! You can easily handle that response like so:
(It works for fromXml(), too!)
Installation
Install ApiProblem like any other Composer package:
composer require crell/api-problem
See the Composer documentation for more details.
Security
If you discover any security related issues, please use the GitHub security reporting form rather than the issue queue.
Credits
- [Larry Garfield][link-author]
- [All Contributors][link-contributors]
License
This library is released under the MIT license. In short, "leave the copyright statement intact, otherwise have fun." See LICENSE for more information.
Contributing
Pull requests accepted! The goal is complete conformance with the IETF spec.