json-api / client
There is no license information available for the latest version (dev-master) of this package.
Simple JSON RESTful api client library
dev-master
2020-05-28 21:25 UTC
Requires
- php: >=7.1
- ext-curl: *
- ext-json: *
- guzzlehttp/psr7: ~1.4
- psr/http-message: ~1.0
- psr/log: ~1.0
Requires (Dev)
- phpunit/phpunit: ~7.5
This package is auto-updated.
Last update: 2024-10-19 22:22:31 UTC
README
Example:
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'