Download the PHP package antonioprimera/laravel-api-client without Composer
On this page you can find all versions of the php package antonioprimera/laravel-api-client. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package laravel-api-client
Laravel Api Client
Installation
Install the pacakage via composer
composer require antonioprimera/laravel-api-client
If you want to use pre-configured clients and endpoints, rather than define authentication types, credentials, request methods and urls as part of your php code, you can create a new config file, named apiEndpoints.php.
Usage
The ApiClient can be used either based on a config file or by just creating and specifying all necessary authentication details in the code.
Example Usage without config
Create a Laravel Sanctum client. The Laravel Sanctum client will send its authentication token in the Authorization header, as the Bearer token.
Create a http client with basic authentication. This type of authentication requires the credentials to be set as an array with the username and password keys. These credentials will be encoded and sent in the Authorization header.
Create a http client with query authentication. For this type of authentication, the credentials are sent via query parameters in the url for get request or via the request body, for other request methods. You can provide any set of authentication data (not necessary username and password, like in the basic http authentication protocol).
The example below will make a get request to:
http://my-api-endpoint-url.com?user=my-user-name&pass=my-pass&tk=my-token&id=15
Example Usage with config (see sample config below)
Create a laravel sanctum client based on the configured client 'mySanctumClient' and call a configured endpoint. If the api token is provided in the config, you can just call a configured endpoint or some other url. If the token is not available in the config, you must use the withCredentials(...) or setCredentials() method, before calling any endpoint / url.
Create a http client with basic authentication. If the credentials are provided in the config, you can just call a configured endpoint or some other url. If the credentials are not available in the config, you must use the withCredentials(...) method or the setCredentials(), before calling the endpoint.
Create a http client with query authentication. For this type of authentication, the credentials are sent via query parameters in the url for get request or via the request body, for other request methods.
You can use a configured client to make calls to endpoints with a given url, so it's not mandatory to configure all endpoints. Just call the 'get' / 'post' / 'put' / 'patch' / 'delete' / 'head' method on the client and provide the necessary data.
Config
By default, the config file apiEndpoints.php is used, so don't forget to create it if you want to use the api client based on config data.
If you want to use another config file, or to change the behavior of the ApiClient class, you must create your own ApiClient class in your project, inheriting the AntonioPrimera\ApiClient\ApiClient. Then you can override the static variable $config to point to your desider config file
The Api client can be used also without a config, by specifying the http client type, the authentication type, the credentials, the url and the method to be used to make the request.