https://github.com/indragunawan/rest-service
Provides an implementation of the Guzzle Command library.
https://github.com/indragunawan/rest-service
php
Last synced: 11 months ago
JSON representation
Provides an implementation of the Guzzle Command library.
- Host: GitHub
- URL: https://github.com/indragunawan/rest-service
- Owner: IndraGunawan
- License: mit
- Created: 2016-08-12T17:43:55.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2017-12-14T09:30:23.000Z (over 8 years ago)
- Last Synced: 2025-08-06T02:22:21.294Z (11 months ago)
- Topics: php
- Language: PHP
- Size: 48.8 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
RestService
===========
[](https://github.com/indragunawan/rest-service/blob/master/LICENSE)
[](https://api.travis-ci.org/IndraGunawan/rest-service.svg?branch=master)
[](https://scrutinizer-ci.com/g/indragunawan/rest-service)
[](https://scrutinizer-ci.com/g/indragunawan/rest-service/code-structure)
[](https://insight.sensiolabs.com/projects/8d1ecd53-bef1-4cca-b598-512676a54f58)
Provides an implementation of the Guzzle Command library that uses services specification to describe web services.
Installation
------------
Require the library with composer:
``` bash
$ composer require indragunawan/rest-service
```
Composer will install the library to your project’s `vendor/indragunawan/rest-service` directory.
Usage
-----
```php
'httpbin API',
'endpoint' => '{endpoint}',
'defaults' => [
'endpoint' => [
'rule' => 'required | url', // see: http://www.sirius.ro/php/sirius/validation/validation_rules.html
'defaultValue' => 'http://httpbin.org',
],
],
'operations' => [
'postTest' => [
'httpMethod' => 'POST', // header, uri, query, body
'requestUri' => '/post',
'request' => [
'type' => 'map', // map, list
'members' => [
'Name' => [
'locationName' => 'name',
'type' => 'string', // string, integer, float, number, boolean, datetime
'rule' => 'required',
],
'CreatedAt' => [
'type' => 'datetime',
'defaultValue' => 'now',
'format' => 'd M y',
],
],
],
'response' => [
'members' => [
'url' => [
'type' => 'string',
'format' => 'format_%s',
]
]
],
],
],
];
```
```php
use IndraGunawan\RestService\ServiceClient;
$config = [
'httpClient' => [
// use by GuzzleClient
],
'defaults' => [
// default value for services specification
],
];
$cacheDir = __DIR__.'/../cache'; // optional, default: null
$debug = false; // optional, default: false
$service = new ServiceClient(__DIR__.'/httpbin-v1.php', $config, $cacheDir, $debug);
$result = $service->postTest([
'Name' => 'My Name',
]);
echo $result['url']; // format_http://httpbin.org/post
// var_dump($result->toArray());
```
Todo
----
* Add more tests.
* Add more documentation.
* Parse Response to Model