PHPackages                             laravel-enso/api - 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. laravel-enso/api

ActiveLibrary[API Development](/categories/api)

laravel-enso/api
================

External service integrations and API logging for Laravel Enso

1.15.8(1mo ago)023.6k↓35.1%2[1 PRs](https://github.com/laravel-enso/api/pulls)4MITPHPPHP ^8.2

Since Mar 13Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/laravel-enso/api)[ Packagist](https://packagist.org/packages/laravel-enso/api)[ Docs](https://github.com/laravel-enso/api)[ RSS](/packages/laravel-enso-api/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (15)Versions (72)Used By (4)

API
===

[](#api)

[![License](https://camo.githubusercontent.com/58c10ca36840131eb0d8f93a1580d98a6fc597c445ebf08b3301b0d4ffdb3752/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f6170692f6c6963656e7365)](LICENSE)[![Stable](https://camo.githubusercontent.com/f50e37c8e597699e3d80bda5d992cde427e1b782d35c1565113630e4db2ddc15/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f6170692f76657273696f6e)](https://packagist.org/packages/laravel-enso/api)[![Downloads](https://camo.githubusercontent.com/de3cac3a55c427edd4664c1502ae1293724a1170e292ce8a85b7bdef4478686f/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2d656e736f2f6170692f646f776e6c6f616473)](https://packagist.org/packages/laravel-enso/api)[![PHP](https://camo.githubusercontent.com/da7cf113b588d26fe679dfefe4a15009272ed358ad4e786ad3c78b45faa61d69/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d382e322532422d3737376262342e737667)](composer.json)[![Issues](https://camo.githubusercontent.com/e21241b4204b2fa396957c7aab9233fd59edbb50f604874d3cb48022ef140c4e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f6c61726176656c2d656e736f2f6170692e737667)](https://github.com/laravel-enso/api/issues)[![Merge Requests](https://camo.githubusercontent.com/c4010bc64e0cefc05cb12eb17842bb214506bcd7300e09cf18c34ef882abdb78/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732d70722f6c61726176656c2d656e736f2f6170692e737667)](https://github.com/laravel-enso/api/pulls)

Description
-----------

[](#description)

API is Laravel Enso's reusable package for external service integrations and inbound API request logging.

It provides a small action-based client on top of Laravel's HTTP client, optional SOAP transport through PHP's `SoapClient`, reusable contracts for authentication, retries, query parameters, file uploads, form payloads, and timeouts. On top of that, it standardizes inbound and outbound API logging, admin notifications for failed calls, and small payload-building helpers used across Enso integrations.

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

[](#installation)

This package comes pre-installed in Laravel Enso distributions that integrate external services or expose protected internal API endpoints.

For standalone package installation inside an Enso-based application:

```
composer require laravel-enso/api
```

The package auto-registers its service provider, loads its migrations, and registers:

- the `api-action-logger` middleware alias
- the `core-api` middleware group
- the `enso.api` configuration namespace

Run the migrations after installation:

```
php artisan migrate
```

If you need to inspect raw request and response traffic during integration work, enable the debug flag in your environment:

```
API_DEBUG=true
```

Features
--------

[](#features)

- Wraps outbound integrations in `Action` classes that resolve and execute `Endpoint` definitions.
- Builds requests through Laravel's HTTP client with support for:
    - bearer-token authentication
    - basic authentication
    - custom headers
    - query parameters
    - form submissions
    - file attachments
    - custom timeouts
    - retry policies
- Supports SOAP integrations through `SoapEndpoint`, `SoapApi`, `SoapResponse`, and the optional `Endpoints\Soap` base class.
- Refreshes an expiring auth token once automatically when an authenticated endpoint receives `401` or `403` on the first try.
- Logs outbound calls in `api_logs`, including URL, route, HTTP method, status, attempt number, payload, direction, and duration.
- Logs inbound calls through the `ApiLogger` middleware and reports non-`200` responses to administrators.
- Provides a read-only `System > API Logs` table, with filters for user, permission, method, direction, and creation datetime.
- Queues `ApiCallError` notifications to active Enso admins on the `notifications` queue using shared `laravel-enso/mails` layouts and package-owned previews.
- Provides `Resource` and `Filter` base classes for payload shaping and input validation.
- Includes a `Throttle` helper for debouncing repeated external API calls.
- Ships the `api_logs` migration and an `Api\Models\Log` model with Enso caching traits.

::: tip Tip If an endpoint implements `UsesAuth` and the first response is `401` or `403`, `Api::call()` refreshes the token once through the token provider before continuing with the normal retry flow. :::

Usage
-----

[](#usage)

### Outbound action

[](#outbound-action)

Define a small endpoint class that describes the request:

```
use LaravelEnso\Api\Contracts\Endpoint;
use LaravelEnso\Api\Enums\Method;

class FetchOffers implements Endpoint
{
    private array $filters = [];

    public function method(): Method
    {
        return Method::GET;
    }

    public function url(): string
    {
        return 'https://posf.ro/api/v1/comparator';
    }

    public function filters(array $filters): self
    {
        $this->filters = $filters;

        return $this;
    }

    public function body(): array
    {
        return $this->filters;
    }
}
```

Wrap it in an `Action` and call `handle()`:

```
use LaravelEnso\Api\Action;

class FetchOffersAction extends Action
{
    public function __construct(private array $filters)
    {
    }

    protected function endpoint(): Endpoint
    {
        return (new FetchOffers())->filters($this->filters);
    }
}

$response = (new FetchOffersAction([
    'request' => 'comparator-electric',
    'tip_client' => 'casnic',
]))->handle();

$payload = $response->json();
```

### SOAP action

[](#soap-action)

SOAP integrations use the same `Action` orchestration and logging flow. Extend the optional SOAP endpoint base class when the operation can be represented by `wsdl()`, `operation()`, and `arguments()`:

```
use LaravelEnso\Api\Endpoints\Soap;

class SubmitInvoice extends Soap
{
    public function __construct(private Invoice $invoice)
    {
    }

    public function wsdl(): ?string
    {
        return config('services.invoices.wsdl');
    }

    public function operation(): string
    {
        return 'SubmitInvoice';
    }

    public function arguments(): array
    {
        return [[
            'number' => $this->invoice->number,
            'total' => $this->invoice->total,
        ]];
    }

    public function options(): array
    {
        return [
            'trace' => true,
            'exceptions' => true,
            'connection_timeout' => 30,
        ];
    }
}
```

Then return the SOAP endpoint from an action:

```
use LaravelEnso\Api\Action;
use LaravelEnso\Api\Contracts\Endpoint;

class SubmitInvoiceAction extends Action
{
    public function __construct(private Invoice $invoice)
    {
    }

    protected function endpoint(): Endpoint
    {
        return new SubmitInvoice($this->invoice);
    }
}

$response = (new SubmitInvoiceAction($invoice))->handle();

$result = $response->body();
```

SOAP responses are wrapped in `SoapResponse`. Failed SOAP calls return a failed response internally, are logged, trigger the normal notification flow, and then throw the original `SoapFault` from `handle()`.

### Inbound logging

[](#inbound-logging)

Use the standalone middleware alias when you only want request logging:

```
Route::middleware(['auth', 'api-action-logger'])
    ->prefix('internal')
    ->group(function (): void {
        Route::post('sync', SyncController::class)->name('internal.sync');
    });
```

Or use Enso's `core-api` middleware group when the route also needs active-state checks, permission checks, and localisation handling:

```
Route::middleware(['auth', 'core-api'])
    ->prefix('api')
    ->group(function (): void {
        Route::post('calendar/events', EventController::class)->name('calendar.events.store');
    });
```

### Resource and filter helpers

[](#resource-and-filter-helpers)

Use `Resource` when a payload needs nested resource resolution and mandatory attribute validation:

```
use LaravelEnso\Api\Resource;

class OfferResource extends Resource
{
    public function __construct(private array $offer)
    {
    }

    public function toArray(): array
    {
        return [
            'id' => $this->offer['id'],
            'supplier' => $this->offer['supplier'],
        ];
    }

    protected function mandatoryAttributes(): array
    {
        return ['id', 'supplier'];
    }
}
```

Use `Filter` when you want to reject unsupported keys before sending them to the remote service:

```
use LaravelEnso\Api\Filter;

class OfferFilters extends Filter
{
    public function allowed(): array
    {
        return ['request', 'tip_client', 'consum_lunar'];
    }
}

$filters = (new OfferFilters($input))->toArray();
```

API
---

[](#api-1)

### Core classes

[](#core-classes)

- `LaravelEnso\Api\Api`Builds and executes the HTTP request, applies optional contracts, tracks attempt count, refreshes bearer tokens once when needed, and retries failed calls when the endpoint allows it.
- `LaravelEnso\Api\SoapApi`Builds and executes SOAP calls through PHP's `SoapClient`, applies SOAP headers when provided, tracks attempt count, and retries `SoapFault` failures when the endpoint allows it.
- `LaravelEnso\Api\SoapResponse`Wraps successful SOAP results and failed `SoapFault` instances behind the response methods used by `Action`.
- `LaravelEnso\Api\Action`Orchestrates one outbound call, measures duration, persists the outbound log entry, reports failures, and returns either an `Illuminate\Http\Client\Response` for HTTP endpoints or a `SoapResponse` for SOAP endpoints.
- `LaravelEnso\Api\Endpoints\Soap`Optional base class for SOAP endpoints. It maps SOAP calls onto the existing `Endpoint` contract by defaulting `method()` to `Method::POST`, `url()` to the WSDL, location, or operation, and `body()` to the SOAP arguments.

### Contracts

[](#contracts)

Required contract:

- `Endpoint`Defines `method()`, `url()`, and `body()`.

Optional contracts:

- `Client`Internal transport contract implemented by `Api` and `SoapApi`.
- `UsesAuth`Adds bearer token support through a token provider.
- `UsesBasicAuth`Adds HTTP basic authentication.
- `CustomHeaders`Adds arbitrary request headers.
- `QueryParameters`Appends `parameters()` to the request URL.
- `Retry`Enables retries through `tries()` and `delay()`.
- `Timeout`Sets a custom HTTP timeout.
- `AsForm`Sends the payload as form data.
- `AttachesFiles`Attaches files to the pending request.
- `SoapEndpoint`Extends `Endpoint` and defines `wsdl()`, `operation()`, `arguments()`, and `options()` for SOAP calls.
- `SoapHeaders`Adds SOAP headers through `SoapClient::__setSoapHeaders()`.
- `Token`Defines the token provider contract used by `UsesAuth`.

::: warning Note SOAP support is additive. Existing HTTP endpoints keep using the same `Endpoint` contract and `Api` client behavior. Applications only need the PHP SOAP extension when they actually use `SoapEndpoint`. :::

### Middleware

[](#middleware)

- `api-action-logger`Alias for `LaravelEnso\Api\Http\Middleware\ApiLogger`
- `core-api`Middleware group registered by the service provider:
    - `LaravelEnso\Core\Http\Middleware\VerifyActiveState`
    - `LaravelEnso\Api\Http\Middleware\ApiLogger`
    - `LaravelEnso\Permissions\Http\Middleware\VerifyRouteAccess`
    - `LaravelEnso\Localisation\Http\Middleware\SetLanguage`

### Log model and storage

[](#log-model-and-storage)

`LaravelEnso\Api\Models\Log`

Stored attributes:

- `user_id`
- `route`
- `url`
- `payload`
- `method`
- `status`
- `try`
- `direction`
- `duration`
- `created_at`
- `updated_at`

Relationships and casts:

- `user()`Belongs to `LaravelEnso\Users\Models\User`
- `payload`Cast to array
- `method`Cast to `LaravelEnso\Api\Enums\Method`
- `direction`Cast to `LaravelEnso\Api\Enums\Direction`

Logging directions:

- `Direction::Inbound`
- `Direction::Outbound`

### API Logs table

[](#api-logs-table)

The package provides the `System > API Logs` table through:

- `GET /api/system/apiLogs/initTable`
- `GET /api/system/apiLogs/tableData`
- `GET /api/system/apiLogs/exportExcel`

Permissions:

- `system.apiLogs.index`
- `system.apiLogs.initTable`
- `system.apiLogs.tableData`
- `system.apiLogs.exportExcel`

The table defaults to `api_logs.created_at desc`, exposes `created_at` as a `datetime` column, displays resolved users and permissions, and supports filters for user, permission, method, direction, and creation datetime.

### Upgrade notes

[](#upgrade-notes)

This release changes the public logging enum contract:

- replace `LaravelEnso\Api\Enums\Calls` with `LaravelEnso\Api\Enums\Direction`
- replace `Calls::Inbound` / `Calls::Outbound` with `Direction::Inbound` / `Direction::Outbound`
- replace `LaravelEnso\Api\Enums\Methods` with `LaravelEnso\Api\Enums\Method`
- replace `Method::get`, `Method::post`, `Method::put`, and `Method::delete` with `Method::GET`, `Method::POST`, `Method::PUT`, and `Method::DELETE`
- update endpoint signatures from `method(): string` to `method(): Method`
- update application code or reporting queries that reference `api_logs.type` to use `api_logs.direction`
- update frontend API log filters from `apiLogMethods` to `apiLogMethod`

After updating the package, run:

```
composer update laravel-enso/api
php artisan enso:upgrade
```

### Resource, filter, and throttle helpers

[](#resource-filter-and-throttle-helpers)

- `Resource::resolve()`Resolves nested resources and validates mandatory attributes.
- `Resource::collection()`Maps a collection into resolved resource arrays.
- `Resource::toJson()`Serializes the resource payload.
- `Filter::toArray()`Rejects unsupported keys before returning the filter array.
- `Throttle::__invoke()`Debounces repeated calls by sleeping until the configured interval has elapsed.

::: warning Note Inbound logging reports any non-`200` response through `ApiCallError`, while outbound actions report failed responses and thrown exceptions through the same notification pipeline.

The notification handler targets active Enso admins and queues the email on the `notifications` queue. :::

Depends On
----------

[](#depends-on)

Required Enso packages:

- [`laravel-enso/core`](https://docs.laravel-enso.com/backend/core.html) [↗](https://github.com/laravel-enso/core)
- [`laravel-enso/enums`](https://docs.laravel-enso.com/backend/enums.html) [↗](https://github.com/laravel-enso/enums)
- [`laravel-enso/helpers`](https://docs.laravel-enso.com/backend/helpers.html) [↗](https://github.com/laravel-enso/helpers)
- [`laravel-enso/localisation`](https://docs.laravel-enso.com/backend/localisation.html) [↗](https://github.com/laravel-enso/localisation)
- [`laravel-enso/menus`](https://docs.laravel-enso.com/backend/menus.html) [↗](https://github.com/laravel-enso/menus)
- [`laravel-enso/mails`](https://github.com/laravel-enso/mails)
- [`laravel-enso/migrator`](https://docs.laravel-enso.com/backend/migrator.html) [↗](https://github.com/laravel-enso/migrator)
- [`laravel-enso/permissions`](https://docs.laravel-enso.com/backend/permissions.html) [↗](https://github.com/laravel-enso/permissions)
- [`laravel-enso/rememberable`](https://docs.laravel-enso.com/backend/rememberable.html) [↗](https://github.com/laravel-enso/rememberable)
- [`laravel-enso/tables`](https://docs.laravel-enso.com/backend/tables.html) [↗](https://github.com/laravel-enso/tables)
- [`laravel-enso/upgrade`](https://docs.laravel-enso.com/backend/upgrade.html) [↗](https://github.com/laravel-enso/upgrade)
- [`laravel-enso/users`](https://docs.laravel-enso.com/backend/users.html) [↗](https://github.com/laravel-enso/users)

Framework dependency:

- [Laravel framework ↗](https://github.com/laravel/framework)

Contributions
-------------

[](#contributions)

are welcome. Pull requests are great, but issues are good too.

Thank you to all the people who already contributed to Enso!

###  Health Score

58

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity27

Limited adoption so far

Community23

Small or concentrated contributor base

Maturity80

Battle-tested with a long release history

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~32 days

Recently: every ~0 days

Total

60

Last Release

43d ago

Major Versions

0.9.9 → 1.0.02021-04-05

PHP version history (3 changes)0.9.1PHP &gt;=7.4.0

1.1.0PHP ^8.0

1.12.3PHP ^8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/16073274?v=4)[Adrian Ocneanu](/maintainers/aocneanu)[@aocneanu](https://github.com/aocneanu)

---

Top Contributors

[![aocneanu](https://avatars.githubusercontent.com/u/16073274?v=4)](https://github.com/aocneanu "aocneanu (32 commits)")[![vmcvlad](https://avatars.githubusercontent.com/u/37445394?v=4)](https://github.com/vmcvlad "vmcvlad (32 commits)")[![gandesc](https://avatars.githubusercontent.com/u/14071925?v=4)](https://github.com/gandesc "gandesc (6 commits)")[![AbdullahiAbdulkabir](https://avatars.githubusercontent.com/u/33360580?v=4)](https://github.com/AbdullahiAbdulkabir "AbdullahiAbdulkabir (3 commits)")[![GITmanuela](https://avatars.githubusercontent.com/u/44998004?v=4)](https://github.com/GITmanuela "GITmanuela (2 commits)")[![tedipop16](https://avatars.githubusercontent.com/u/71398467?v=4)](https://github.com/tedipop16 "tedipop16 (1 commits)")

---

Tags

apilaravel-enso

### Embed Badge

![Health badge](/badges/laravel-enso-api/health.svg)

```
[![Health](https://phpackages.com/badges/laravel-enso-api/health.svg)](https://phpackages.com/packages/laravel-enso-api)
```

###  Alternatives

[laravel-enso/core

The backend shell of a Laravel Enso application

3465.3k205](/packages/laravel-enso-core)[laravel-enso/roles

Role management for Laravel Enso

1044.9k32](/packages/laravel-enso-roles)[laravel-enso/localisation

Language and translation management for Laravel Enso

1362.8k10](/packages/laravel-enso-localisation)[laravel-enso/permissions

Permission management for Laravel Enso

1244.2k51](/packages/laravel-enso-permissions)[laravel-enso/tutorials

Tutorial management backend for Laravel Enso

1140.7k](/packages/laravel-enso-tutorials)[laravel-enso/data-import

Excel Importer dependency for Laravel Enso

2044.0k6](/packages/laravel-enso-data-import)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
