joseluisq / guztav
This package is abandoned and no longer maintained.
No replacement package was suggested.
A small RESTful API client around PHP Guzzle
1.0.2
2017-05-02 20:22 UTC
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
,Request
andResponse
objects. - Some helper functions for more friendly
Response
data handling like :$response->toArray()
,$response->toString()
, etc. - You can define your
BASE_URI
andACCESS_TOKEN
settings via.env
file. 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_uri
param forClient
settings.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