Data Response 1.0.0
2021-06-21
1441次浏览
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
- html
- bootstrap
- release
- redis
- Yii 1.1
- apidoc
- mongodb
- http
- db
- validation
- cache
- Yii 2.0
- runner
- extensions
- console
- gii
- error handler
- mailer
- http 客户端
- queue
- twig
- translator
- hydrator
- widget
- sphinx
- log
- assets
- config
- router
- middleware
- symfonymailer
- elasticsearch
- widgets
- swiftmailer
- imagine
- 图书
- rbac
- swagger
- data
- csrf
- logging
- fastroute
- application