kovagoz / http-responder
A simple solution to create PSR-7 compatible HTTP responses.
Installs: 14
Dependents: 1
Suggesters: 1
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/kovagoz/http-responder
Requires
- php: ^8.0
- psr/http-factory: ^1.0
- psr/http-message: ^1.0
Requires (Dev)
- nyholm/psr7: ^1.4
- phpunit/phpunit: ^9.4.0
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2025-09-23 06:34:48 UTC
README
A simple solution to create PSR-7 compatible HTTP responses.
Requirements
- PHP >=8.0
Usage
Instantiate the class:
$responder = new HttpResponder($responseFactory, $streamFactory);
Create HTML response
$response = $responder->reply('hello world');
Create JSON response
$response = $responder->reply(['foo' => 'bar']);
In this case, response body will be the following:
{ "foo": "bar" }
Furthermore, Content-Type
header will be set to application/json
.
Create empty response (204 No Content)
$response = $responder->reply();
Create redirection
$response = $responder->redirect('https://example.com/');
Default status code is 302
. You can change it on the response object by the
withStatus()
method.
You can also pass UriInterface
object to the redirect()
method instead of
string URL.
Testing
This repository contains a Makefile which aids to run unit tests on your computer using a Docker container.
Just run the command below, sit back and watch results.
make test