23/07
2018
Wallogit.com
2017 © Pedro Peláez
Parsing JSON response for REST API with CORS management
Parsing JSON response for Slim v3 REST API with CORS management - https://projects.alal.io, (*1)
Before we get started, please make sure that you have installed Slim 3 Framework. I was using slim-born from HavenShen for developing this module., (*2)
$ composer require malfasih/slim3-json-parser
or, (*3)
composer.json, (*4)
"require": {
"malfasih/slim3-json-parser": "@dev"
}
<?php
require __DIR__ . '/../vendor/autoload.php';
$app = new \Slim\App();
$container = $app->getContainer();
$container['json'] = function($container) {
return new \Malfasih\Slim\JsonParser();
};
Just with a single line of code, and it actually works., (*5)
<?php
public function getUserData($request, $response)
{
return $this->json->print($response, true, 'OK');
}