Download the PHP package stoyantodorov/laravel-api-client without Composer
On this page you can find all versions of the php package stoyantodorov/laravel-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download stoyantodorov/laravel-api-client
More information about stoyantodorov/laravel-api-client
Files in stoyantodorov/laravel-api-client
Package laravel-api-client
Short Description API client for Laravel
License MIT
Homepage https://github.com/stoyantodorov/laravel-api-client
Informations about the package laravel-api-client
Laravel HTTP Facade wrapper and Token service
This package provides a way to use Laravel HTTP facade with error handling, logging and events firing. There is also Token Service that makes requests to retrieve access token depending on stored configurations or received parameters.
Installation
Usage
HttpClient Service
Resolve an HttpClient instance in a way that fits what you need, for example:
Send a request:
You can configure PendingRequest in advance:
You can also use baseConfig method to add base configurations:
This method can receive a configured PendingRequest:
Use send method for specific HTTP method and format:
Optionally you can add configured PendingRequest to it too:
When you need to send a request without error handling, logging and event firing may use sendRequest:
Logging and event firing is configurable trough config values:
These configurations can be overridden through HttpClient setters:
Token Service
Factories
There are two factories which instantiate TokenService. The first one sets configurations from config file:
When you are using this factory should set the relevant configurations in api-client.php:
The second factory sets configurations from data objects:
When you are using an endpoint to refresh a token, the factories should be instructed to send such configurations:
You may instruct TokenFromConfigFactory to loads configurations from other config key:
If you have an already received token, can send it to both factories as optional parameter:
Obtain a token
get method sends a token request:
If the service is instantiated with an already obtained token, the method returns it instead of sending a new request.
The same method can also send a request that refreshes the token:
The JSON path to the token in the response should be set in config file:
or in TokenData and RefreshTokenData
When you need to access the response can subscribe for the events which are fired by default:
If you aren't using these events may switch them off from the config file:
or TokenData and RefreshTokenData:
API Reference
HttpClientInterface
Enums
TokenFromConfigFactoryInterface
TokenFromDataFactoryInterface
TokenInterface
Testing
Changelog
Please see CHANGELOG for more information on what has changed recently.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-api-client with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0