joseluisq / guztav
A small RESTful API client around PHP Guzzle
Installs: 25
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
pkg:composer/joseluisq/guztav
Requires
- php: >=7.0
- guzzlehttp/guzzle: ^6.2
Requires (Dev)
- phpunit/phpunit: ^6.0
- vlucas/phpdotenv: ^2.4
This package is not auto-updated.
Last update: 2022-05-27 12:04:24 UTC
README
A small RESTful API client around PHP Guzzle.
Features
- It's only a wrapper around Guzzle. It means that you can use the same API like:
Client,RequestandResponseobjects. - Some helper functions for more friendly
Responsedata handling like :$response->toArray(),$response->toString(), etc. - You can define your
BASE_URIandACCESS_TOKENsettings via.envfile. For example using Dotenv package (optional).
Install
composer require joseluisq/guztav
Usage
Settings via .env file
# Define your API settings GUZTAV_BASE_URI='http://localhost:8001/api/v1/' GUZTAV_ACCESS_TOKEN='eyJ0eXBiOiJKV1QiLCN0bx.....'
GUZTAV_BASE_URI: The same Guzzlebase_uriparam forClientsettings.GUZTAV_ACCESS_TOKEN: It will be to added to the current header likeAuthorization: Bearer ...(optional)
Settings via constructor
You can also pass the same Guzzle options for Client object.
<?php use Guztav\Client; // Setting the client $client = new \Guztav\Client([ // Define these params if you don't use some .env file 'base_uri' => 'http://localhost:8001/api/v1/', 'access_token' => 'eyJ0eXBiOiJKV1QiLCN0bx.....', // Optional // More options... 'headers' => ['Accept' => 'application/json'], 'timeout' => 2.0, ... ]);
Making a request
<?php use Guztav\Client; $client = new \Guztav\Client(); // My GET request $response = $client->get('client/1', [ 'query' => ['a' => 1, 'b' => 2] ]); $string = $response->toString(); // My JSON POST request $params = [ 'name' => 'Octocat', 'email' => 'octo.cat@github.com', ]; $array = $client->post('client', [ 'json' => $params ])->toArray();
Note: By now, Guztav supports application/json response data only.
License
MIT license
© 2017 José Luis Quintana