Skip to content

chatwork/slim-json-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

slim-json-request

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

About

Slim middleware for supporting post json

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published