rami / problem-detail-bundle
A Symfony bundle that implements application/problem+json to give meaning to api response errors
Installs: 381
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/rami/problem-detail-bundle
Requires
- php: ^8.3
- symfony/http-foundation: ^6.4 || ^7.0 || ^8.0
- symfony/http-kernel: ^6.4 || ^7.0 || ^8.0
Requires (Dev)
- phpunit/phpunit: ^12.3
- symfony/phpunit-bridge: ^6.4 || ^7.0 || ^8.0
README
RFC 9457: Problem Details for HTTP API deprecated by RFC 9457
Implementation of the RFC 9457 to give meaning to HTTP Response Errors
A simple bundle
Composer installation:
composer require rami/problem-detail-bundle
example use:
use Symfony\Component\HttpFoundation\Response; use Rami\ProblemDetailBundle\ProblemResponse\ProblemJsonResponse; use Symfony\Component\HttpFoundation\JsonResponse; class ArticleController { public function addArticle(): Response { ... if (false === $user->canPostArticle()) { return new ProblemJsonResponse(Response::HTTP_FORBIDDEN, title: "Insufficient permission", detail: "You have insufficient permission to add a new article"); } ... return new JsonResponse(['status' => 'created', 'id' => $article->getId()]); } }
This will return an application/problem+json response
{
"type": "about:blank",
"title": "Insufficient permission",
"status": 404,
"detail": "You have insufficient permission to add a new article"
}