Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/stas-dovgodko/restful_api_client

Simple PHP REST API client with models mapping
https://github.com/stas-dovgodko/restful_api_client

php rest-api restfull-api

Last synced: about 1 month ago
JSON representation

Simple PHP REST API client with models mapping

Awesome Lists containing this project

README

        

Example:

```php
require_once 'vendor/autoload.php';

class JSONPlaceholder extends \JsonAPI\Model {
use \JsonAPI\Resource;

protected $endpoint = 'https://jsonplaceholder.typicode.com/todos';

public static function FromArray(array $data)
{
$object = new self;

// @todo Schema validation here
$object->userId = $data['userId'];
$object->id = $data['id'];
$object->title = $data['title'];

return $object;
}

/**
* Get object by ID
*
* @param $id
* @return JSONPlaceholder
* @throws \JsonAPI\Client\Exception
*/
public function get($id)
{
return $this->request($id, 'GET', [], self::class);
}

public function getId() : string
{
return $this->id;
}

public function getUserId() : string
{
return $this->userId;
}

public function getTitle() : string
{
return $this->title;
}
}


$test = new JSONPlaceholder;
$object = $test->setAdapter(new \JsonAPI\Client\Adapter\Curl())->get(1);

echo $object->getId().' - '.$object->getTitle(); // will echo '1 - delectus aut autem'
```