chatwork / slim-json-request
Slim 中间件,支持 JSON 请求
dev-master
2015-07-08 03:17 UTC
Requires
- slim/slim: 2.*
Requires (Dev)
- phpunit/phpunit: *
- there4/slim-test-helpers: dev-master
This package is not auto-updated.
Last update: 2024-09-28 16:39:06 UTC
README
Slim 中间件,支持 POST JSON
安装
使用 composer。
{ "require": { "slim/slim": "2.4.*", "chatwork/slim-json-request": "dev-master" } }
用法
在您的 Slim
应用程序中添加 Chatwork\JsonRequestMiddleware
。
<?php require __DIR__ . '/vendor/autoload.php'; use Slim\Slim; use Chatwork\JsonRequestMiddleware; $app = new Slim(array( 'debug' => true, )); $app->add(new JsonRequestMiddleware()); $app->post('/messages', function() use ($app) { // Set json data to `$app->json_body` as array. echo $app->json_body['msg']; }); $app->run();
执行 HTTP 请求
[cw-tanaka@macbook] % curl -H'Content-Type: application/json' https://:9876/messages -X POST -d '{
"msg": "hogehoge"
}'
hogehoge
查看 测试案例。
许可协议
MIT