Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/stas-dovgodko/restful_api_client
- Owner: stas-dovgodko
- Created: 2019-07-23T10:47:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-04-19T19:22:21.000Z (over 1 year ago)
- Last Synced: 2024-05-18T21:42:48.467Z (8 months ago)
- Topics: php, rest-api, restfull-api
- Language: PHP
- Homepage:
- Size: 26.4 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
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'
```