Weave Code
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

Http Message Util Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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);

Implementation Patterns

  • Middleware Guard Clauses: Use RequestMethodInterface::METHOD_* constants to validate or route by method without typos.
  • Consistent Error Responses: In custom exception handlers, map exceptions to status codes via StatusCodeInterface::STATUS_*, ensuring consistency across your API.
  • API Documentation Generators: Integrate constants to ensure OpenAPI/Swagger specs reference standardized status codes (e.g., STATUS_UNPROCESSABLE_ENTITY for 422).
  • Testing Assertions: Use constants in PHPUnit tests to avoid brittle comparisons ($this->assertEquals(StatusCodeInterface::STATUS_CREATED, $response->getStatusCode())).
  • Trait-Based Convenience: Create a HttpConstants trait to import frequently used constants (e.g., use StatusCodeInterface as Status;) for DRY code.

Gotchas and Tips

  • Not a PSR-7 Implementation: This package does not provide Request/Response classes—pair it with symfony/http-foundation, guzzlehttp/psr7, or nyholm/psr7.
  • Laravel Redundancy: Laravel already exposes identical constants via Illuminate\Http\Response (e.g., Response::HTTP_CREATED). Using both can cause inconsistency—pick one convention.
  • Stable but Inactive: Last updated in 2020, but constants are unlikely to change (HTTP spec is stable). Safe for production, but don’t expect new features.
  • No psr/http-message dependency (since v1.1.4): Eliminates transitive conflicts, but you still need a separate PSR-7 implementation.
  • PHP 8+ Requirement: Use ^1.1.5 to ensure PHP 8 compatibility (v1.1.5+).
  • Debugging Tip: If autoloading fails, run composer dump-autoload -o—this is rare but can occur in legacy setups without Composer’s autoloader enabled.
  • Avoid Dual Usage: In Laravel apps, prefer native Response::HTTP_* constants to prevent confusion (e.g., Response::HTTP_GATEWAY_TIMEOUT vs STATUS_GATEWAY_TIMEOUT).
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.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4