reedware/laravel-api

Adds configurable web api connections to your Laravel application.

v1.1.0 2020-09-12 13:39 UTC

This package is auto-updated.

Last update: 2024-11-12 22:26:10 UTC


README

This package adds configurable web api connections to your Laravel application.

Installation

Require this package with composer.

composer require reedware/laravel-api

Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the service provider or facade. However, should you still need to reference them, here are their class paths:

\Reedware\LaravelApi\ApiServiceProvider::class // Service Provider
\Reedware\LaravelApi\Facade::class // Facade

Configuration

You can configure your various api endpoints by using the ~/config/api.php configuration file.

'connections' => [

    'api-name' => [
        'host' => env('API_HOST'),
        'username' => env('API_USERNAME'),
        'password' => env('API_PASSWORD'),
        'options' => [
            'json' => true,
            'expects_json' => true
        ]
    ]

]

Usage

You can now connect to your api using Api::connection('api-name'), and subsequently create requests for it:

Api::connection('api-name')->request()->url('my/endpoint')->post([
    'my-form-data' => 'with-values'
]);