Data Response 1.0.0
2021-06-21
1286次浏览
First version of yiisoft/data-response pacakge was released.
The package allows responding with data that is then automatically converted into PSR-7 response using one of the formatters such as JSON or XML.
use Yiisoft\DataResponse\DataResponseFactory;
use Yiisoft\DataResponse\Formatter\JsonDataResponseFormatter;
/**
* @var Psr\Http\Message\ResponseFactoryInterface $responseFactory
*/
// Usually in controller:
$factory = new DataResponseFactory($responseFactory);
$dataResponse = $factory->createResponse(['best' => 'test']);
// Usually done automatically via one of middleware provided by the pacakge:
$dataResponse = $dataResponse->withResponseFormatter(new JsonDataResponseFormatter());
$dataResponse->getBody()->rewind();
echo $dataResponse->getHeader('Content-Type'); // ["application/json; charset=UTF-8"]
echo $dataResponse->getBody()->getContents(); // {"best": "test"}
There is also a middleware for negotiating content so formatter could be chosed based on Content-Type
header sent by the client.
新闻归档
热门标签
- yii3
- 扩展
- 发布
- yii2
- debug
- view
- auth client
- bootstrap
- html
- release
- apidoc
- redis
- Yii 2.0
- mongodb
- Yii 1.1
- extensions
- mailer
- gii
- console
- http 客户端
- runner
- validation
- twig
- queue
- cache
- translator
- hydrator
- widget
- http
- sphinx
- error handler
- db
- config
- log
- symfonymailer
- router
- elasticsearch
- swagger
- assets
- swiftmailer
- 图书
- imagine
- csrf
- IDE
- i18n
- definitions
- rbac
- user
- smarty
- logging