chatwork/slim-json-request

Slim middleware for supporting json request

dev-master 2015-07-08 03:17 UTC

This package is not auto-updated.

Last update: 2022-01-22 02:21:39 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