criztianix / php-spore2
SPORE, a generic ReST client
1.1.5
2017-06-12 13:48 UTC
Requires
- php: ~7.0
- doctrine/annotations: 2.0.x-dev
- guzzlehttp/guzzle: ^6.0
Requires (Dev)
- phpunit/phpunit: 5.3.*
README
SPORE, a generic ReST client for PHP7
require_once("vendor/autoload.php"); use PHP_Spore\Spore;
Now, you can generate a spore object from an array
$spore = Spore::newFromArray([ "base_url" => "https://httpbin.org", "methods" => [ "get" => [ "path" => "/get", "method" => "GET" ], "query_params" => [ "path" => "/response-headers", "method" => "GET", "params" => [ "limit" => [ "required" => true ] ] ], "post" => [ "path" => "/post", "method" => "POST" ] ] ]);
or you can use a json file with the spec.
$spore = Spore::newFromJson(__DIR__ . "spec.json");
Request and enpoint is very easy
$response = $spore->post([ "params" => [ "limit" => 10, "page" => 1 ], "form-data" => [ "data" => [ 1,2,3 ] ] ]);
Spore now support hydrate models from api response.
$spec = [ "base_url" => "https://httpbin.org", "methods" => [ "getCache" => [ "path" => "/cache", "model" => "PHP_Spore\\Test\\Response\\Cache" ] ] ]
and our cache model, look like this:
<?php namespace PHP_Spore\Test\Response; use \PHP_Spore\Spore_Property; class Cache { public $url; /** * @Spore_Property(class = "PHP_Spore\Test\Response\Headers") */ public $headers; } class Headers { public $Host; }