chatwork / slim-json-request
Slim middleware for supporting json request
Installs: 85 547
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 9
Forks: 1
Open Issues: 3
Requires
- slim/slim: 2.*
Requires (Dev)
- phpunit/phpunit: *
- there4/slim-test-helpers: dev-master
This package is not auto-updated.
Last update: 2024-12-21 17:53:46 UTC
README
Slim middleware for supporting post json
Installation
Using composer.
{ "require": { "slim/slim": "2.4.*", "chatwork/slim-json-request": "dev-master" } }
Usage
Add Chatwork\JsonRequestMiddleware
in your Slim
application.
<?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();
Execute http request:
[cw-tanaka@macbook] % curl -H'Content-Type: application/json' http://localhost:9876/messages -X POST -d '{
"msg": "hogehoge"
}'
hogehoge
See Testcase.
LICENSE
MIT