Download the PHP package drewlabs/http-query without Composer
On this page you can find all versions of the php package drewlabs/http-query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package http-query
HTTP Query
This library provides a client side implementation of HTTP query (similar to graphql) that allows developpers to easily customize data requested from web resources (that support the server side language implementation) and directly sending complex query parameters.
Usage
Query builder
The library comes with a query builder class that provides a fluent interface for building and compiling queries. An example is as follow:
- Creating a query object
As seen above, the API comes with numerous fluent methods for defining query intention:
- eq
The eq
method allow developpers to build a COLUMN=VALUE
like query:
- neq
The neq
is the inverse of the eq
query method:
- lte / lt
The lte
and lt
respectively allow developper to construct a query that check if a column value is less than (less than or equal to) a given value.
- gte / gt
The gte
and gt
respectively allow developper to construct a query that check if a column value is greater than (greater than or equal to) a given value.
- in
The in
clause search for value that exists in a list of provided values:
- exists
The exists
clause allow to query for relationship existance in the database.
- sort
The sort
clause allow developpers to apply a sort by column
on the result set:
Note The sort order is defined by an integer value. Any value greater than 0
get converted to ASC
while any value less than 0
is converted to DESC
- select
The select
clause allows developpers to specify the list of columns to select from the query server:
Note As shown in the examples above, query
object provides a fluent api
for building complex queries using PHP function calls.
Executing composed query
After building query using the fluent API, developpers can send query requests to backend servers using the execute
method:
Aggregation framework
The query
api also support some aggregation method for performing basic mathematic computation on the resource being selected instead of returning an entire collection:
-
min(string column, string relation)
: return the minimum value of the column in the selected resource table -
max(string column, string relation)
: return the maximum value of the column in the selected resource table -
sum(string column, string relation)
: computes and return the sum of all values in the given column in the selected resource table -
avg(string column, string relation)
: computes and return the average of all values in the given column in the selected resource table count(string column, string relation)
: Count the total elements matching matching the provided query parameters.
Note All aggregation method support a second parameter allowing developpers to query a releated resource in the application database.