06/12
2017
dev-master
9999999-devMaking API calls from laravel applications
MIT
The Requires
by basemkhirat
Making API calls from laravel applications
composer require basemkhirat/api
Basemkhirat\API\APIServiceProvider::class
'API' => Basemkhirat\API\Facades\API::class
php artisan vendor:publish
// $config is optional GET Request : API::get("users/show", $config) POST Request : API::post("users/create", $config) PUT Request : API::put("users/update", $config) DELETE Request : API::delete("users/delete", $config)
// $config is optional GET Request : API::get("http://httpbin.org/get", $config) POST Request : API::post("http://httpbin.org/post", $config) PUT Request : API::put("http://httpbin.org/put", $config) DELETE Request : API::delete("http://httpbin.org/delete", $config)
API::get("get", $config)->getBody()->getContent()
API::get("get", $config)->toArray()
API::get("get", $config)->getStatusCode() // int 200
In api.php config file, repeat default
array block, (*1)
return [ // Called using API::driver("default")->get($uri) or API::get($uri) directly "default" => [ 'base_uri' => 'http://site1.dev/api/', .... ... . ], // Called using API::driver("another")->get($uri) "another" => [ 'base_uri' => 'http://site2.dev/api/', .... ... . ] ];
//API::guzzle() return guzzle client object API::guzzle()->get("get", $config)->getBody()->getContents();
For more guzzle request options, (*2)
Browse Guzzle docs : Guzzle Docs, (*3)
Good luck
, (*4)
Dont forget to send a feedback..
, (*5)
Making API calls from laravel applications
MIT