1. Go to this page and download the library: Download nylo/smalljson 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/ */
// per route / group
Route::middleware('smalljson')->group(function () {
Route::apiResource('users', UserController::class);
});
// or for the whole API, in bootstrap/app.php (Laravel 11+)
->withMiddleware(function (Middleware $middleware) {
$middleware->api(append: [\SmallJson\Http\Middleware\SmallJsonResponses::class]);
})
use SmallJson\Facades\SmallJson;
$envelope = SmallJson::encode($data); // string, honours config modes
$data = SmallJson::decode($envelope, true); // assoc arrays; false for stdClass