/slim3-json-parser

Parsing JSON response for Slim v3 REST API with CORS management

Primary LanguagePHPMIT LicenseMIT

slim3-json-parser

Parsing JSON response for Slim v3 REST API with CORS management - https://projects.alal.io

Installation

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.

$ composer require malfasih/slim3-json-parser

or

composer.json

"require": {
    "malfasih/slim3-json-parser": "@dev"
}

Registering Component

<?php
require __DIR__ . '/../vendor/autoload.php';
$app = new \Slim\App();
$container = $app->getContainer();

$container['json'] = function($container) {
	return new \Malfasih\Slim\JsonParser();
};

Testing

Just with a single line of code, and it actually works.

<?php

public function getUserData($request, $response)
{
  return $this->json->print($response, true, 'OK');
}