Skip to content

Repository files navigation

Fast Forward HTTP Message

PHP VersionComposer PackagePSR-7TestsCoverageDocsLicenseGitHub Sponsors

A modern PHP library for working with PSR-7 HTTP Messages, focusing on immutability, strict typing, and developer ergonomics. Part of the Fast Forward ecosystem.


✨ Features

  • ✅ Fully PSR-7 compliant
  • ✅ Strictly typed for PHP 8.3+
  • ✅ Immutable by design (PSR-7 standard)
  • ✅ Convenient JSON, HTML, Text, Empty, and Redirect responses
  • ✅ Payload-aware interfaces for reusable patterns
  • ✅ No external dependencies beyond PSR-7

📦 Installation

composer require fast-forward/http-message

Requirements: PHP 8.3+, Composer


🛠️ Usage

JSON Response Example

useFastForward\Http\Message\JsonResponse;
$response = newJsonResponse(['success' => true]);
echo$response->getStatusCode(); // 200echo$response->getHeaderLine('Content-Type'); // application/json; charset=utf-8echo (string) $response->getBody(); // {"success":true}

Payload Access and Immutability

$newResponse = $response->withPayload(['success' => false]);
echo$response->getPayload()['success']; // trueecho$newResponse->getPayload()['success']; // false

Text Response Example

useFastForward\Http\Message\TextResponse;
$text = newTextResponse('Hello, world!');

Empty Response Example

useFastForward\Http\Message\EmptyResponse;
$empty = newEmptyResponse();

Redirect Response Example

useFastForward\Http\Message\RedirectResponse;
$redirect = newRedirectResponse('https://example.com', true); // Permanent redirect

🧰 API Summary

Class/MethodDescriptionDocs
JsonResponseJSON response with automatic headersdocs
TextResponsePlain text responsedocs
HtmlResponseHTML response with correct Content-Typedocs
EmptyResponseHTTP 204 No Content responsedocs
RedirectResponseHTTP redirect response (301/302)docs
getPayload()Returns the payload of the responsedocs
withPayload($data)Returns a new instance with a different payloaddocs

🔌 Integration

  • Works out of the box with any PSR-7 compatible framework or library
  • Designed to extend and complement nyholm/psr7
  • Can be used with fast-forward/container for dependency injection

📁 Directory Structure Example

src/
├── EmptyResponse.php
├── HtmlResponse.php
├── JsonResponse.php
├── TextResponse.php
├── RedirectResponse.php
├── ...

⚙️ Advanced/Customization

  • Extend any response class to add custom logic
  • Compose with other PSR-7 middlewares or response decorators
  • All interfaces are public and designed for extension

🛠️ Versioning & Breaking Changes

  • v1.4: PHP 8.3+ required, stricter typing, improved docs
  • v1.0: Initial release

❓ FAQ

Q: What PHP version is required?
A: PHP 8.3 or higher.

Q: Is this library PSR-7 compliant?
A: Yes, all responses and streams are fully PSR-7 compliant and extend Nyholm's implementation.

Q: How do I create a JSON response?
A: Use JsonResponse and pass your payload to the constructor. The Content-Type header is set automatically.

Q: How do I work with payloads?
A: Use getPayload() to retrieve the payload and withPayload($payload) to create a new instance with a different payload.

Q: Can I use this with any framework?
A: Yes, as long as your framework supports PSR-7 messages.

Q: How do I handle authentication headers?
A: Use the Authorization header utility and credential classes for parsing and handling authentication schemes.


🛡 License

MIT © 2026 Felipe Sayão Lobato Abreu


🤝 Contributing

Contributions, issues, and feature requests are welcome!
Feel free to open a GitHub Issue or submit a Pull Request.


🔗 Links

Releases

Sponsor this project

Packages

Used by

Contributors

Languages