2017 © Pedro Peláez
 

library lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

image

ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  • Tuesday, May 23, 2017
  • by ngabor84
  • Repository
  • 0 Watchers
  • 1 Stars
  • 183 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 2 % Grown

The README.md

Lumen API query parser

Codeship Status for ngabor84/lumen-api-query-parser, (*1)

Description

This is a simple request query parameter parser for REST-APIs based on Laravel's Lumen framework., (*2)

Requirements

  • PHP >=7.1
  • Lumen framework >= 5.4
  • Mockery >= 0.9 (dev)
  • PHPUnit >= 6.1 (dev)
  • PHP CodeSniffer >= 3.0.0 RC4 (dev)

Installation

  • Add ngabor84/lumen-api-query-parser to your composer.json and make composer update, or composer require ngabor84/lumen-api-query-parser ~1.0
  • Setup the service provider: in bootstrap/app.php add the following line: php $app->register(LumenApiQueryParser\Provider\RequestQueryParserProvider::class);

Usage

    // app/API/V1/Models/UserController.php
    namespace App\Api\V1\Http\Controllers;

    use App\Api\V1\Models\User;
    use App\Api\V1\Transformers\UserTransformer;
    use LumenApiQueryParser\ResourceQueryParserTrait;
    use LumenApiQueryParser\BuilderParamsApplierTrait;

    class UserController extends Controller
    {
        use ResourceQueryParserTrait;
        use BuilderParamsApplierTrait;

        public function index(Request $request)
        {
            $params = $this->parseQueryParams($request);
            $query = User::query();
            $userPaginator = $this->applyParams($query, $params);

            $this->response->paginator($userPaginator, new UserTransformer, ['key' => 'users']);
        }
    }

Query syntax

Eager loading

Q: /users?connection[]=profile
R: will return the collection of the users with their profiles included, (*3)

Filtering

Q: /users?filter[]=name:ct:admin
R: will return the collection of the users whose names contains the admin string, (*4)

Available filter options, (*5)

Operator Description Example
ct String contains name:ct:Peter
nct String NOT contains name:nct:Peter
sw String starts with username:sw:admin
ew String ends with email:ew:gmail.com
eq Equals level:eq:3
ne Not equals level:ne:4
gt Greater than level:gt:2
ge Greater than or equal level:ge:3
lt Lesser than level:lt:4
le Lesser than or equal level:le:3
in In array level:in:1|2|3

Sorting

Q: /users?sort[]=name:ASC
R: will return the collection of the users sort by their names ascending, (*6)

Pagination

Q: /users?limit=10&page=3
R: will return a part of the collection of the users (from the 21st to 30th), (*7)

The Versions

23/05 2017

dev-master

9999999-dev https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser

23/05 2017

1.2.3

1.2.3.0 https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser

17/05 2017

1.2.2

1.2.2.0 https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser

17/05 2017

1.2.1

1.2.1.0 https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser

17/05 2017

1.2.0

1.2.0.0 https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser

09/05 2017

1.1.0

1.1.0.0 https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser

03/05 2017

1.0.0

1.0.0.0 https://github.com/ngabor84/lumen-api-query-parser

A query parser for REST-APIs based on laravel's lumen framework

  Sources   Download

MIT

The Requires

 

The Development Requires

api lumen query parser