tobiassjosten / responsible-service-provider
一个用于自动响应格式化的Silex ServiceProvider。
1.0.0
2016-09-22 12:51 UTC
Requires
- silex/silex: ~2.0
- symfony/serializer: ~2.1|~3.0
Requires (Dev)
- symfony/browser-kit: ~2.1|~3.0
This package is not auto-updated.
Last update: 2024-09-23 11:31:12 UTC
README
一个用于自动响应格式化的Silex ServiceProvider。
安装
-
将包添加到您的composer.json文件中
$ composer require tobiassjosten/responsible-service-provider
(对于Silex 1,请将0.0.1版本添加到该命令的末尾。)
-
在您的应用程序中注册它。
$app->register(new \Tobiassjosten\Silex\ResponsibleServiceProvider());
用法
启用后,只需让您的控制器返回数组形式的数据。 ResponsibleServiceProvider
会完成其余工作。
$app->get('/foo', function () {
return ['Bar'];
});
在JSON中
$ curl -I -H 'Accept: application/json' http://example.com/foo
HTTP/1.1 200 OK
Date: Tue, 07 May 2013 08:30:58 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/json
["Bar"]
和在XML中
$ curl -I -H 'Accept: application/xml' http://example.com/foo
HTTP/1.1 200 OK
Date: Tue, 07 May 2013 08:30:58 GMT
Server: Apache/2.2.22 (Ubuntu)
X-Powered-By: PHP/5.4.9-4ubuntu2
Cache-Control: no-cache
Transfer-Encoding: chunked
Content-Type: application/xml
<?xml version="1.0"?>
<response><item key="0">Bar</item></response>