kovagoz/http-responder
Composer 安装命令:
composer require kovagoz/http-responder
包简介
A simple solution to create PSR-7 compatible HTTP responses.
README 文档
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
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 1
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-22