media24si/api-resource

Laravel Guzzle Api Resource Package
2,542 8
Install
composer require media24si/api-resource
Latest Version:v3.0.1
PHP:^8.0
Laravel:4 – 10
License:MIT
Last Updated:Jan 15, 2024
Links: GitHub  ·  Packagist
Maintainer: BostjanOb

Api Resource

Software License

A simple Guzzle wrapper, providing easy access to API endpoints.

For Guzzle v5.0 support use v1.0.0

Install - Laravel

Require this package with Composer (Packagist), using the following command:

$ composer require media24si/api-resource

Register the ApiResourceServiceProvider to the providers array in config/app.php:

Media24si\ApiResource\ApiResourceServiceProvider::class,

Publish vendor files (config file):

$ php artisan vendor:publish

Optional Register the facade in config/app.php:

'Api' => Media24si\ApiResource\Facades\ApiResource::class

Install - Lumen

Require this package with Composer (Packagist), using the following command:

$ composer require media24si/api-resource

Register the ApiResourceServiceProvider inside bootstrap/app.php (Lumen):

$app->register(Media24si\ApiResource\ApiResourceServiceProvider::class);

Copy the config file from the vendor vendor/media24si/api-resource/src/config/apiresrouce.php to your local config folder config/apiresource.php and enable the config inside your bootstrap/app.php (Lumen):

$app->configure('apiresource');

Optional Register the facade in bootstrap/app.php (Lumen):

class_alias(Media24si\ApiResource\Facades\ApiResource::class, 'Api');

also, make sure you uncomment this line from the same file:

$app->withFacades();

Usage

You can use this package without any configuration. Just use the \Api facade in your controller (or inject Media24si\ApiResource\ApiResource in your function/controller).

Call your endpoints, like you would a normal Guzzle request:

\Api::get('http://httpbin.org'); // returns a response object

Config

defaults

Associative array of Request Options, that are applied to every request, created by the client. See the official manual .

Example:

'defaults' => [
	'base_uri' => 'http://httpbin.org/']
]

#### endpoints
Array of defined endpoints. Here you can define your aliases for endpoints.

Sample array:
``` php
'endpoints' => [
	'notification' => [
		'uri' => 'http://httpbin.org/notification'
	],
	'categories' => [
		'uri' => '/categories', // with base_uri set
		'options' => [
			'query' => [
				'fields' => 'id, title'
			]
		]
	]
]

With endpoints defined you can make simple calls. A sample would be:

\Api::get('notification')

Default options can be overridden:

\Api::get('categories', ['query' => ['fields' => 'id, title, slug']])

License

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

Related Packages

spondonit/zttp

A developer-experience focused HTTP client, optimized for most common use cases.

6,251 0
kozz/laravel-guzzle-provider

Guzzle 5/6 Service Provider for Laravel

1,110,076 62
carsdotcom/php-request-class

Structure the logic around Guzzle API requests into object-oriented classes

31,798 2
eleme/laravel-guzzle

laravel guzzle service provider

6,607 6
chiefgroup/laravel-guzzle

Chiefgroup Laravel Interface API Use

4,960 2

Version History

Version Released PHP Laravel License
v3.0.1 ^8.0 * MIT
v3.0 ^8.0 * MIT
v2.0.6 >=7.0 * MIT
v2.0.5 >=7.0 5.* || 6.* MIT
v2.0.4 >=7.0 5.* || 6.* MIT