2017 © Pedro Peláez
 

library json-api-request

A package for handling JSON API requests

image

giadc/json-api-request

A package for handling JSON API requests

  • Tuesday, September 26, 2017
  • by giadc-dev
  • Repository
  • 4 Watchers
  • 1 Stars
  • 367 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 18 Versions
  • 3 % Grown

The README.md

JSON API Request

A package for automating pagination, filtering, sorting, and includes when working with the JSON API standard., (*1)

Installation

composer install giadc/json-api-request, (*2)

Basic Usage

RequestParams

Request Params provides objects for pulling/modifying HttpFoundation Requests that compile with JSON API V1.0., (*3)

Example:, (*4)

GET /articles?include=author,comments.author&page[number]=3&page[size]=20&filter[author]=frank&sort=-created,title&fields[author]=name,age

```php use Giadc\JsonApiRequest\Requests\RequestParams;, (*5)

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

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

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

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

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

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

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


### Request Objects All Objects implements the RequestInterface and give access the following methods: `getParamsArray()`, `getQueryString()` #### Includes ```php $includes = new Includes(['author', 'comments.author'); $includes->add('site'); $includes->getQueryString(); //outputs: 'include=author,comments.author,site'

Pagination

Pagination sets a defaults the pages size if not provided. It will Also allow you to set max it is able to return by settings the PAGINATION_DEFAULT and PAGINATION_MAX env variables., (*13)

$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

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

Filters

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

Excludes

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

Fields

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

The Versions

26/09 2017

1.0.x-dev

1.0.9999999.9999999-dev

A package for handling JSON API requests

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

26/09 2017

dev-master

9999999-dev

A package for handling JSON API requests

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

26/09 2017

1.1.0

1.1.0.0

A package for handling JSON API requests

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

02/05 2017

1.0.1

1.0.1.0

A package for handling JSON API requests

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

14/03 2017

dev-f-and-boolean-search

dev-f-and-boolean-search

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

14/03 2017

0.5.0-alpha

0.5.0.0-alpha

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

22/12 2016

1.0.0

1.0.0.0

A package for handling JSON API requests

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

14/12 2016

0.4.4

0.4.4.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

13/12 2016

0.4.3

0.4.3.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

05/12 2016

0.4.2

0.4.2.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

22/11 2016

0.4.1

0.4.1.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

18/11 2016

0.4.0

0.4.0.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

The Development Requires

by David Hill
by Ryan Marganti

05/08 2016

0.3.1

0.3.1.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

by David Hill
by Ryan Marganti

24/03 2016

0.3.0

0.3.0.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

by David Hill
by Ryan Marganti

08/03 2016

0.2

0.2.0.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

by David Hill
by Ryan Marganti

07/03 2016

0.1.2

0.1.2.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

by David Hill
by Ryan Marganti

07/03 2016

0.1.1

0.1.1.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

by David Hill
by Ryan Marganti

29/02 2016

0.1

0.1.0.0

A package for handling JSON API requests with Doctrine

  Sources   Download

MIT

The Requires

 

by David Hill
by Ryan Marganti