PHP code example of giadc / json-api-request

1. Go to this page and download the library: Download giadc/json-api-request 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/ */

    

giadc / json-api-request example snippets


use Giadc\JsonApiRequest\Requests\RequestParams;

// By default it creates params from Globals 
$request = new RequestParams();

// Get Includes
$request->getIncludes()->toArray();
// outputs: ['author', 'comments.author']

// Get Page Details
$request->getPageDetails()->toArray();
// outputs: ['page' => ['number => 3, 'size' => 20]]

// Get Sorting
$request->getSortDetails()->toArray();
// outputs: [['field' => 'title', 'direction' => 'ASC'], ['field' => 'created', 'direction' => 'DESC']]

// Get Filters
$request->getFiltersDetails()->toArray();
// outputs: ['author' => ['frank']]

// Get Full Pagination
$request->getFullPagination();
// outputs: [{Pagination}, {Includes}, {Sorting}, {Filters}]

// Get Fields
$request->getFields()->toArray();
// outputs: ['author' => ['name', 'age']]

$$/outputs: '

$pagination = new Pagination(2, 20);
$pagination->getQueryString();
//outputs: 'page[number]=2&page[size]=20'

// PAGINATION_MAX=25
$pagination = new Pagination(2, 1000);
$pagination->getQueryString();
//outputs: 'page[number]=2&page[size]=25'

$sorting = new Sorting('-created,title');
$sorting->setSorting();
$sorting->getQueryString('created,-title');
//outputs: 'sort=created,title'

$filters = new Filters(['author' => 'frank');
$filters->addFilter('author', 'bob');
$filters->getQueryString();
//outputs: 'filter[author]=frank,bob'

$filters = new Excludes(['author' => 'country');
$filters->add('author', 'age');
$filters->getQueryString();
//outputs: 'excludes[author]=country,age'

$filters = new Fields(['author' => 'name');
$filters->add('author', 'age');
$filters->getQueryString();
//outputs: 'fields[author]=name,age'