-
allows for configuration via a config file
-
provides magic methods for all verbs
-
implements ApiRunnerInterface for dependancy injection
NOTE: assumes plural endpoint contains the data portion of the response
e.g.
{users => [{"user":123},{"user":456}]}
Add dws/api-gateway
as a requirement to composer.json:
{
"require": {
"dws/api-gateway": "dev-master"
}
}
Get all users
$gateway = new Dws\ApiGateway|ApiGateway;
$users = $gateway->getUsers();
Get a user by unique id
$user = $gateway->getUsers(123, true);
Get users at least 21
$users = $gateway->getUsers("?where[]=age:gte:21");
See Slender Api Consumer Documentation for more on query strings.
Creating a new user
$data = ['username'=>'kermit', 'email' => 'kermitfrog@gmail.com'];
$user = $gateway->postUsers($data);
Editing a user
$data = ['email' => 'misspiggy@gmail.com'];
$user = $gateway->putUsers(123, $data);
Delete a user
$response = $gateway->deleteUsers(123);
explicity adding criteria by name (where, order, fields only)
$criteria = new Dws\ApiGateway\Criteria;
$criteria = $criteria->add("where", "name:jon");
$users = $gateway->getUsers($criteria);
implicitly adding criteria
//where
$criteria->where("name:jon");
//or
$criteria = $criteria->where(["age:21", "sex:M"]);
//fields
$criteria->fields("name");
//or
$criteria->fields(["age", "sex"]);
//or
$criteria = $criteria->fields("position,salary");
//order
$criteria->order("name:asc");
//or
$criteria->order(["age:desc", "sex:desc"]);
//or
$criteria = $criteria->order("position:asc,salary:desc");
explicit aggregates
$criteria->where("sex:M");
$criteria = $criteria->aggregate("max:age");
implicit aggregates
//count
$criteria->where("sex:M");
$criteria = $criteria->count();
//max
$criteria = $criteria->max('age');
//min
$criteria = $criteria->min('age');
pagination
//take
$criteria = $criteria->take(10);
//skip
$criteria = $criteria->skip(10);
chaining
$criteria = $criteria->where("sex:M")
->order('age:asc')
->take(10)
->skip(10);
1.0.8
feature: make auth endpoint replaceable
1.0.7
Bug: rename dist back to php
1.0.6
Feature: convert config to tokenized dist files
2.0.4 and 1.0.4
Feature: exclude unwanted options
Bugfix: fix for encoding problem on early posts and puts
various additional bugfixes
2.0.1
bugfix: update singular response to array
2.0.0
return array instead on object
v0.1.2
1) Auth
v0.1.1
1) move client configuration setters to sub array 'client'
2) fix "//" bug when path is "/"