PHP code example of cristianp6 / slim-json-api-helper

1. Go to this page and download the library: Download cristianp6/slim-json-api-helper library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

cristianp6 / slim-json-api-helper example snippets



use Slim\Http\Request as Request;
use JsonApiHelper\Renderer;

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

// register the json response and error handlers
$jsonApiHelper = new JsonApiHelper\JsonApiHelper($app->getContainer());
$jsonApiHelper->registerResponseResult();
$jsonApiHelper->registerErrorHandlers();


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

    $this->result->data = [
        'user_id' => $user_id
    ];

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

  });
}