staskjs / simple-api
Library for creating simple api wrappers for php
Installs: 3 351
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- guzzlehttp/guzzle: ^6.2
This package is not auto-updated.
Last update: 2024-11-10 02:50:08 UTC
README
Installation
composer require staskjs/simple-api
Usage
Create class for your api wrapper.
use Staskjs\SimpleApi\SimpleJsonApi;
class GithubApi extends SimpleJsonApi {
// Headers for each request
protected $headers = [
'Authorization' => 'token TOKEN',
];
// Specify default query params for each request (for example this can be api version or api token)
protected $default_query = [
];
public function getUsers() {
return $this->request('GET', 'users');
}
}
// ...
$api = new GithubApi('https://api.github.com');
$success = $api->getUsers();
// If http query was successful
if ($success) {
$data = $api->getData();
}
else {
$errors = $api->getErrors();
}