PHP Classes

PHP API JSON Response: Generate HTTP responses in JSON format

Recommend this page to a friend!
  Info   View files Example   View files View files (15)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2023-11-30 (1 month ago) RSS 2.0 feedNot yet rated by the usersTotal: 58 This week: 1All time: 10,441 This week: 108Up
Version License PHP version Categories
response-json-php-li 7.0.0Custom (specified...7.1HTTP, Text processing, PHP 7
Description 

Author

This package can generate HTTP responses in JSON format.

It can take a list of values to generate a response.

The package generates a string representing the list of values after being encoded in JSON format.

Picture of Leonardo Di Sarli
  Performance   Level  
Name: Leonardo Di Sarli <contact>
Classes: 10 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 4x

Winner: 1x

Example

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
ResponseJson\ResponseJson;

$responseJson = new ResponseJson();

$token = [
   
'token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' .
       
'eyJhdWQiOiJ0ZXN0IiwiZXhwIjozMCwiaWF0I' .
       
'joxNTYyMTcwOTIwLCJpc3MiOiJ0ZXN0Iiwic3' .
       
'ViIjoiIn0=.wPdhZtjpyBjObFWbxPx33GNJpv' .
       
'KHIznPV0GQ2NiQp5A=',
   
'valid_until' => '2020-06-16 12:36:34',
];

$data = [
   
'data' => 'test',
];

$response = $responseJson->response(
   
'd0684895-cb6c-4c9a-a0aa-0aed7cfc1f46',
   
microtime(true)-0.1,
   
$token,
   
$data,
   
'message'
);

print_r($response);
echo
PHP_EOL;

$responseDelete = $responseJson->responseDelete();
print_r($responseDelete);


Details

PHP Response Json

Latest Version codecov CI Build Downloads Old Downloads PRs Welcome Packagist License (custom server)

PHP library to create a response json pattern to API's

Installation

Release 7.0.0 Requires PHP 8.3

Release 6.0.0 Requires PHP 8.2

Release 5.0.0 Requires PHP 8.1

Release 4.0.0 Requires PHP 7.4

Release 3.0.0 Requires PHP 7.3

Release 2.0.0 Requires PHP 7.2

Release 1.0.0 Requires PHP 7.1

The recommended way to install is through Composer.

composer require not-empty/response-json-php-lib

Usage

Creating a response

use ResponseJson\ResponseJson;
$responseJson = new ResponseJson();
$token = [
    'token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.' .
        'eyJhdWQiOiJ0ZXN0IiwiZXhwIjozMCwiaWF0I' .
        'joxNTYyMTcwOTIwLCJpc3MiOiJ0ZXN0Iiwic3' .
        'ViIjoiIn0=.wPdhZtjpyBjObFWbxPx33GNJpv' .
        'KHIznPV0GQ2NiQp5A=',
    'valid_until' => '2020-06-16 12:36:34',
];
$data = [
    'data' => 'test',
];
$response = $responseJson->response(
    'd0684895-cb6c-4c9a-a0aa-0aed7cfc1f46',
    microtime(true)-0.1,
    $token,
    $data,
    'message'
);
var_dump($response);

if you want an environment to run or test it, you can build and install dependences like this

docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/response-json-php-lib:php83 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/response-json-php-lib:php83 bash

Verify if all dependencies is installed

composer install --no-dev --prefer-dist

and run

php sample/response-json-sample.php

Development

Want to contribute? Great!

The project using a simple code. Make a change in your file and be careful with your updates! Any new code will only be accepted with all validations.

To ensure that the entire project is fine:

First you need to building a correct environment to install all dependences

docker build --build-arg PHP_VERSION=8.3-rc-cli -t not-empty/response-json-php-lib:php83 -f contrib/Dockerfile .

Access the container

docker run -v ${PWD}/:/var/www/html -it not-empty/response-json-php-lib:php83 bash

Install all dependences

composer install --dev --prefer-dist

Run all validations

composer check

Not Empty Foundation - Free codes, full minds


  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagecontrib (4 files)
Files folder imagesample (1 file)
Files folder imagesrc (1 file)
Files folder imagetests (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file composer.lock Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpmd.xml Data Auxiliary data
Accessible without login Plain text file phpunit.xml Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file php.yml Data Auxiliary data

  Files folder image Files  /  contrib  
File Role Description
  Accessible without login Plain text file coverage-checker.php Example Example script
  Accessible without login Plain text file Dockerfile Data Auxiliary data
  Accessible without login Plain text file pre-commit Data Auxiliary data
  Accessible without login Plain text file setup.sh Data Auxiliary data

  Files folder image Files  /  sample  
File Role Description
  Accessible without login Plain text file response-json-sample.php Example Example script

  Files folder image Files  /  src  
File Role Description
  Plain text file ResponseJson.php Class Class source

  Files folder image Files  /  tests  
File Role Description
  Plain text file ResponseJsonTest.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:58
This week:1
All time:10,441
This week:108Up