fig/http-message-util
Utility constants and helpers for PSR-7 HTTP messages: request methods, response status codes and reason phrases, and common header references. Not a PSR-7 implementation—just shared values to standardize HTTP message handling.
Install via Composer:
composer require fig/http-message-util
This package delivers only constants and interfaces—no PSR-7 implementations. Begin by replacing magic numbers and strings with named constants for HTTP methods and status codes. First practical use: define allowed request methods in middleware or assert status codes in tests. Example:
use Fig\Http\Message\StatusCodeInterface;
use Fig\Http\Message\RequestMethodInterface;
// Instead of: if ($request->getMethod() === 'GET') ...
if ($request->getMethod() === RequestMethodInterface::METHOD_GET) { ... }
// Instead of: return new Response(null, 204);
return new Response(null, StatusCodeInterface::STATUS_NO_CONTENT);
RequestMethodInterface::METHOD_* constants to validate or route by method without typos.StatusCodeInterface::STATUS_*, ensuring consistency across your API.STATUS_UNPROCESSABLE_ENTITY for 422).$this->assertEquals(StatusCodeInterface::STATUS_CREATED, $response->getStatusCode())).HttpConstants trait to import frequently used constants (e.g., use StatusCodeInterface as Status;) for DRY code.Request/Response classes—pair it with symfony/http-foundation, guzzlehttp/psr7, or nyholm/psr7.Illuminate\Http\Response (e.g., Response::HTTP_CREATED). Using both can cause inconsistency—pick one convention.psr/http-message dependency (since v1.1.4): Eliminates transitive conflicts, but you still need a separate PSR-7 implementation.^1.1.5 to ensure PHP 8 compatibility (v1.1.5+).composer dump-autoload -o—this is rare but can occur in legacy setups without Composer’s autoloader enabled.Response::HTTP_* constants to prevent confusion (e.g., Response::HTTP_GATEWAY_TIMEOUT vs STATUS_GATEWAY_TIMEOUT).How can I help you explore Laravel packages today?