LaravelPackages.net
Acme Inc.
Toggle sidebar
dot-env-it/laravel-api-integrator

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.

824
8
v1.4.0
About dot-env-it/laravel-api-integrator

dot-env-it/laravel-api-integrator is a Laravel package for 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.. It currently has 8 GitHub stars and 824 downloads on Packagist (latest version v1.4.0). Install it with composer require dot-env-it/laravel-api-integrator. Discover more Laravel packages by dot-env-it or browse all Laravel packages to compare alternatives.

Last updated

Laravel API Integrator

Latest Version on Packagist Total Downloads

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();

Become a sponsor

Your support allows me to keep this package free, up-to-date and maintainable. Alternatively, you can spread the word!

Installation

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'

You can pass config variables to yaml file using !config tag

USAGE

use 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();

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Comments