Download the PHP package phpro/api-problem without Composer
On this page you can find all versions of the php package phpro/api-problem. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download phpro/api-problem
More information about phpro/api-problem
Files in phpro/api-problem
Package api-problem
Short Description RFC7807 Problem details implementation
License MIT
Informations about the package api-problem
Api Problem
This package provides a RFC7807 Problem details implementation. It can be integrated everywhere in your code and should result in a general error response format for HTTP APis.
This package only provides a generic interface, an exception class and some built-in api problem messages. Since handling the exceptions is up to the framework, here is a list of known framework integrations:
- Symfony
^4.1
: ApiProblemBundle
Installation
Usage
This package provides a general interface for creating ApiProblem value objects.
Built-in problems
-
General problems
- ExceptionApiProblem
- HttpApiProblem
-
Symfony integration problems
- ValidationApiProblem
- Http problems
- 400 BadRequestProblem
- 401 UnauthorizedProblem
- 403 ForbiddenProblem
- 404 NotFoundProblem
- 405 MethodNotAllowedProblem
- 409 ConflictProblem
- 412 PreconditionFailedProblem
- 415 UnsupportedMediaTypeProblem
- 418 IAmATeapotProblem
- 422 UnprocessableEntityProblem
- 423 LockedProblem
- 428 PreconditionRequiredProblem
ExceptionApiProblem
Debuggable: The exception
part will only be added in debug context!
`
HttpApiProblem
`
ValidationApiProblem
`
BadRequestProblem
`
UnauthorizedProblem
`
ForbiddenProblem
`
NotFoundProblem
`
MethodNotAllowedProblem
`
ConflictProblem
`
PreconditionFailedProblem
`
UnsupportedMediaTypeProblem
`
IAmATeapotProblem
`
UnprocessableEntityProblem
`
LockedProblem
`
PreconditionRequiredProblem
`
Creating your own problem
Creating problem sounds scary right!? Since the RFC is very loose, we made the interface as easy as possible:
A lot of problems will be detected in an HTTP context. Therefore, we also provided a base HttpApiProblem
class.
This one will automatically fill in the type and title section based on the HTTP code.
The only thing you'll need to do, is add some additional data to it:
If you want to log additional information in a debug context, it is possible to implement an additional DebuggableApiProblemInterface
:
About
Submitting bugs and feature requests
Bugs and feature request are tracked on GitHub. Please take a look at our rules before contributing your code.
License
api-problem is licensed under the MIT License.