PHP code example of alirezajavadi / jsonize

1. Go to this page and download the library: Download alirezajavadi/jsonize 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/ */

    

alirezajavadi / jsonize example snippets


use JSONize\App\Easy\Response;

Response::message("User created")->status(201)->data(["id" => 42]);

$json = Response::message("OK")->status(200)->get();

use JSONize\App\Efficient\Response;

$response = Response::getInstance();

$response->message("User created")->status(201)->data(["id" => 42])->get();

Response::message("Operation successful");

Response::status(404);
Response::status(200, "Everything is fine");

Response::data(["id" => 1, "name" => "Item"]);
Response::data(["id" => 1, "name" => "Item"], "item");

Response::error("Something went wrong");
Response::error("Validation failed", 422);

Response::message("OK")->headers(["X-Request-Id" => "abc-123"]);

Response::message("OK")->status(200)->hideStatus();

$json = Response::message("OK")->get();

Response::message("Users retrieved")
    ->status(200)
    ->data(["users" => [["id" => 1, "name" => "Alice"]]]);

Response::error("Validation failed", 422)
    ->data(["email" => "The email field is 

Response::status(204)->hideMessage()->hideData();