PHPackages                             criztianix/php-spore2 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. criztianix/php-spore2

ActiveLibrary[HTTP &amp; Networking](/categories/http)

criztianix/php-spore2
=====================

SPORE, a generic ReST client

1.1.5(8y ago)38252GNUPHPPHP ~7.0

Since Jan 5Pushed 8y ago1 watchersCompare

[ Source](https://github.com/CriztianiX/PHP-Spore)[ Packagist](https://packagist.org/packages/criztianix/php-spore2)[ RSS](/packages/criztianix-php-spore2/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (12)Used By (0)

PHP-Spore
=========

[](#php-spore)

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:

```
