PHPackages                             aliirfaan/citronel-external-service - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. aliirfaan/citronel-external-service

ActiveLibrary[API Development](/categories/api)

aliirfaan/citronel-external-service
===================================

Consume external APIs using a standard interface using Laravel http client. Log requests and responses for API calls in database and log file for auditing/debugging purposes.

1.0.1(1y ago)0191MITPHPPHP &gt;=8.0.0

Since Nov 27Pushed 1y ago1 watchersCompare

[ Source](https://github.com/aliirfaan/citronel-external-service)[ Packagist](https://packagist.org/packages/aliirfaan/citronel-external-service)[ RSS](/packages/aliirfaan-citronel-external-service/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (4)Used By (1)

Citronel external service
=========================

[](#citronel-external-service)

Consume external APIs using a standard interface.

Features
--------

[](#features)

- Contract class to consume external APIs.
- Takes configuration from a configuration file that follows a standard format.
- Helper function for caching responses.
- Helper classes for events and subscribers.
- **You can use `aliirfaan/citronel-external-service-generator` package as dev dependency to generate config file, service class, migrations, models, events, listeners for your external service.**

Requirements
------------

[](#requirements)

- [Composer](https://getcomposer.org/)
- [Laravel](http://laravel.com/)

Installation
------------

[](#installation)

- Install the package using composer:

```
 $ composer require aliirfaan/citronel-external-service
```

- Install the package with dev dependency:

```
 $ composer require aliirfaan/citronel-external-service --dev
```

Contracts
---------

[](#contracts)

- AbstractExternalService.php
    Your main service class must extend this abstract class.

Traits
------

[](#traits)

- ExternalServiceLogTrait
    Use this trait if we want to log request and responses for external services
- ExternalServiceEventTrait
    Use this trait in your event class
- ExternalServiceEventSubscriberTrait
    Use this trait in your subscriber class

Steps
-----

[](#steps)

1. Create a configuration file with proper values for your external service that follows the format expected by the `AbstractExternalService`.
2. Create your service class and extend `AbstractExternalService`.
3. Use `ExternalServiceLogTrait` if you want to log requests and responses. **This trait expects events, listeners and models to exist for the external service.**
4. Use `ExternalServiceCacheTrait` if you want to cache requests and responses.

Usage
-----

[](#usage)

An example of how to consume an example external service [httpbin](https://httpbin.org/).

Configuration
-------------

[](#configuration)

`app/config/http-bin.config`

```
