Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Api Problem

Api Problem Laravel Package

crell/api-problem

A framework-agnostic PHP library implementing RFC 9457 (formerly RFC 7807) Problem Details for HTTP APIs. It provides structured problem objects, exceptions, and response helpers for consistent, machine-readable API error responses.

View on GitHub
Deep Wiki
Context7

A simple implementation of the api-problem specification. Includes PSR-15 support.

Frequently asked questions about Api Problem
How do I install crell/api-problem in a Laravel application?
Install it with Composer using composer require crell/api-problem. The package is framework-agnostic and does not ship a Laravel service provider or config file, so integration is manual. You typically use its Problem and ApiProblem value objects inside a custom exception renderer or response helper.
Does crell/api-problem work with Laravel 10 and Laravel 11?
Yes, as long as your PHP version satisfies the package constraint. Current releases require PHP 8.1 or newer, which aligns with Laravel 10 and 11 targets. The package does not depend on illuminate components, so it is additive and should not conflict with Laravel dependencies.
How do I return RFC 9457 problem details from a Laravel exception?
Create a custom exception that implements Laravel's Renderable contract or defines a render method. In that renderer, build a Problem or ApiProblem object, serialize it to JSON, and return an Illuminate response with the Content-Type application/problem+json header. Laravel will not automatically render ProblemException because it does not extend Illuminate's exception contract.
Can I use crell/api-problem without PSR-7 or PSR-15 middleware?
Yes. The core value objects can be used standalone as a serialization contract inside Laravel. Do not adopt the PSR-15 middleware path unless your stack already carries PSR-7/15 components, such as a RoadRunner or Swoole deployment. In a standard FPM or Octane Laravel app, the bridge cost usually outweighs the benefit.
What classes does crell/api-problem provide?
The package ships immutable value objects including Problem, ApiProblem, and ProblemException. Problem and ApiProblem represent RFC 9457 payloads, while ProblemException carries a problem object as an exception. Inspect the package source for exact constructors and helper methods because documentation is minimal.
How do I test API error responses that use crell/api-problem in Laravel?
Use Laravel feature tests to assert the HTTP status, the application/problem+json content type, and the JSON structure. Check fields such as type, title, status, detail, and instance with assertJson and assertHeader. The package provides no special testing utilities because it only builds value objects.
Is crell/api-problem production-ready for a Laravel API?
It is technically sound, MIT-licensed, small, readable, and built around a stable RFC. The main concerns are low adoption, few recorded dependents, and a single-maintainer bus factor, so treat it as vendor-adjacent and be prepared to vendor or fork. Also enforce discipline so internal exception messages and stack traces do not leak into the detail field.
How do I handle content negotiation for application/problem+json in Laravel?
You must implement Accept header negotiation yourself in Laravel; the package will not inspect Accept outside its PSR-15 middleware. Check whether the client accepts application/problem+json or application/json and return the problem response only when appropriate. Otherwise fall back to your normal response format.
What are alternatives to crell/api-problem for Laravel API errors?
Alternatives include Symfony's HTTP Problem component, a small custom error DTO inside Laravel's exception handler, or sticking with an existing error envelope that clients already parse. A custom renderer gives you the most control and avoids adding another dependency. Evaluate whether external consumers actually benefit from RFC 9457 compliance before switching.
How is crell/api-problem maintained and what PHP versions does it support?
The package is authored by Larry Garfield, a well-known PHP community maintainer, and follows the stable RFC 9457 specification. Current releases require PHP 8.1 or newer. It has a single maintainer and low dependent count, so monitor releases and consider vendoring the small codebase as a contingency.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo