Package to integrate third party APIs.
Package to simplify third-party api integrations. Make API calls like they are part of your code with this package. No need to remember base url or path of any API. Just call it like Integration::for('api-provider')->getSomethingCool()->json();
Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word!
composer require dot-env-it/laravel-api-integrator
Run install
command to publish config file and yaml file
php artisan api-integrator:install
This command will create api-integrator.yaml
file at root of project and api-integrator.php
file at config
folder
Sample api-integrator.yaml
file
integrations:
github:
url: 'https://api.github.com/'
auth:
type: Bearer
value: !config 'api-integrator.token.github'
name: 'Authorization'
example:
url: 'https://api.example.com'
auth:
type: Header
token: !config 'api-integrator.token.example'
name: 'X-API-KEY'
!config
taguse DotEnvIt\ApiIntegrator\Facades\Integration;
//api url https://api.github.com/foo
Integration::for('github')->get('foo')->json();
//api url https://api.example.com/foo
Integration::for('example')->get('foo')->json();
This package also provides a magic method for each http method
use DotEnvIt\ApiIntegrator\Facades\Integration;
//api url https://api.example.com/foo
Integration::for('example')->getFoo()->json();
//api url https://api.example.com/foo with dynamic token
Integration::for('example')->withToken('new-token')->getFoo()->json();
//api url https://api.example.com/foo with dynamic header
Integration::for('example')->withHeader('X-CUSTOM-HEADER', 'CUSTOM')->withHeader('X-CUSTOM-HEADER-2', 'CUSTOM-2')->getFoo()->json();
//api url https://api.example.com/foo with headers array
Integration::for('example')->withHeaders(['X-CUSTOM-HEADER' => 'CUSTOM', 'X-CUSTOM-HEADER-2' => 'CUSTOM-2'])->getFoo()->json();
//api url https://api.example.com/foo/1
Integration::for('example')->getFoo_id(['id' => 1])->json();
//api url https://api.example.com/foo/1/bar/2
Integration::for('example')->getFoo_foo_id_bar_bar_id(['foo_id' => 1, 'bar_id' => 2])->json();
//api url https://api.example.com/foo/1?foo=bar&bar=baz
Integration::for('example')->getFoo_id(['id' => 1, 'foo' => 'bar', 'bar' => 'baz'])->json();
//POST api url https://api.example.com/foo/1/bar/2/baz
Integration::for('example')->postFoo_foo_id_bar_bar_id_baz(['foo_id' => 1, 'bar_id' => 2])->json();
Please see CONTRIBUTING for details.
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.