org_heigl/slim-json-helpers

Clone of aporat/slim-json-helpers | Slim3 JSON Request & Response Helpers

1.1.1 2021-01-03 03:58 UTC

This package is auto-updated.

Last update: 2024-10-29 04:59:02 UTC


README

A clone of the removed aporat/slim-json-helpers

Latest Stable Version Composer Downloads Build StatusCode Coverage License

Requirements

  • PHP >= 5.5

Usage

use Slim\Http\Request as Request;
use JsonHelpers\Renderer as JsonRenderer;

$app = new \Slim\App($settings);
$container = $app->getContainer();

// register the json response and error handlers
$jsonHelpers = new JsonHelpers\JsonHelpers($app->getContainer());
$jsonHelpers->registerResponseView();
$jsonHelpers->registerErrorHandlers();


$this->post('/users', function (Request $request, Response $response, $args)
{
  $user_id = $request->getParam('user_id');
  
   $data = [
        'user_id' => $user_id
    ];

    $response = $this->view->render($response, 200, $data);
    return $response;

  });
}