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

ActiveLibrary[API Development](/categories/api)

sevaske/laravel-api-response
============================

The package for building clean, consistent, and predictable JSON API responses in laravel applications.

2.0.1(1mo ago)110↓95.2%MITPHPPHP ^8.3CI passing

Since Jan 21Pushed 1mo agoCompare

[ Source](https://github.com/sevaske/laravel-api-response)[ Packagist](https://packagist.org/packages/sevaske/laravel-api-response)[ RSS](/packages/sevaske-laravel-api-response/feed)WikiDiscussions 2.x Synced 1w ago

READMEChangelog (4)Dependencies (14)Versions (8)Used By (0)

Laravel API Response
====================

[](#laravel-api-response)

[![Latest Version on Packagist](https://camo.githubusercontent.com/2be06986d5080ca2de1a2b8d0faef3d19da913f6a8ee398fd38e179ac4bf2059/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73657661736b652f6c61726176656c2d6170692d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sevaske/laravel-api-response)[![Tests](https://github.com/sevaske/laravel-api-response/actions/workflows/CI.yaml/badge.svg)](https://github.com/sevaske/laravel-api-response/actions/workflows/CI.yaml)

**A simple library for a simple task**: building consistent JSON API responses in Laravel. Fully customizable when you need it

Features
--------

[](#features)

- Unified success/error JSON responses
- Response macros
- Global helper
- Configurable response structure
- Custom payload builders
- Laravel paginator support
- Dependency injection friendly

#### Default response format

[](#default-response-format)

Out of the box, the response looks like this:

```
{
  "success": true,
  "message": "OK",
  "data": {
    "id": 1
  }
}
```

Error response:

```
{
  "success": false,
  "message": "Validation failed",
  "errors": {
    "email": "Invalid"
  }
}
```

Response structure is fully configurable through the config file or by replacing the payload builder.

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

[](#requirements)

- PHP ^8.3
- Laravel ^11.0|^12.0|^13.0

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

[](#installation)

```
composer require sevaske/laravel-api-response
```

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

[](#configuration)

Publish the config:

```
php artisan vendor:publish --tag=api-response-config
```

Usage
-----

[](#usage)

#### 1. Dependency Injection (recommended)

[](#1-dependency-injection-recommended)

```
use Sevaske\LaravelApiResponse\Contracts\ApiResponseContract;

class UserController
{
    public function __construct(
        private ApiResponseContract $api
    ) {}

    public function show(User $user)
    {
        return $this->api->success(
            data: $user
        );
    }
}
```

#### 2. Via `response()` macros

[](#2-via-response-macros)

```
return response()->success(
    message: 'OK',
    data: ['id' => 1],
);

return response()->error(
    message: 'Validation failed',
    errors: ['email' => 'Invalid']
);
```

#### 3. Via helper

[](#3-via-helper)

```
return api()->success(
    message: 'OK',
    data: ['id' => 1],
);
```

Pagination
----------

[](#pagination)

Pagination follows **Laravel's native JSON resource behavior**.

If a `JsonResource` or `ResourceCollection` wrapping a paginator is passed as `data`, **all pagination fields generated by Laravel are preserved automatically**.

There is **no custom pagination format** and no additional abstraction layer — the library simply remaps the `data` key while keeping the rest of the response intact.

Supported paginators:

- `LengthAwarePaginator` (`paginate()`)
- `Paginator` (`simplePaginate()`)
- `CursorPaginator` (`cursorPaginate()`)

```
use App\Http\Resources\UserResource;
use App\Models\User;

$users = User::paginate();

return api()->success(
    data: UserResource::collection($users)
);
```

Customization
-------------

[](#customization)

Change response keys:

```
return [
    'success_key' => 'ok',
    'message_key' => 'msg',
    'data_key'    => 'results',
    'errors_key'  => 'errors',
];
```

Change the "success" value format:

```
return [
    'success_value' => 1,
    'error_value'   => 0,
];
```

Extending
---------

[](#extending)

Bind your own response implementation and payload builder

```
// App\Providers\AppServiceProvider.php

use Sevaske\LaravelApiResponse\Contracts\ApiResponseContract;

public function register(): void
{
    $this->app->bind(
        ApiResponseContract::class,
        MyCustomApiResponse::class
    );

    $this->app->bind(
        ApiResponsePayloadContract::class,
        MyPayloadBuilder::class
    );
}
```

This allows full control over the final response structure without touching controllers.

License
-------

[](#license)

[MIT](LICENSE)

###  Health Score

43

—

FairBetter than 89% of packages

Maintenance93

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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 ~29 days

Recently: every ~0 days

Total

7

Last Release

33d ago

Major Versions

0.1.0 → 1.0.02026-07-15

1.0.0 → 2.0.02026-07-15

1.x-dev → 2.x-dev2026-07-15

PHP version history (2 changes)0.1.0PHP ^8.2

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/94643c38672a39a9b675ab6d43f5c1d3c0789300cc052f742a960e0a7d70847e?d=identicon)[sevaske](/maintainers/sevaske)

---

Top Contributors

[![sevaske](https://avatars.githubusercontent.com/u/42838184?v=4)](https://github.com/sevaske "sevaske (28 commits)")

---

Tags

responsejsonapilaravelhttp-responselaravel-apiapi-response

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.1k4.6M319](/packages/laravel-ai)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

818355.4k3](/packages/defstudio-telegraph)[moonshine/moonshine

Laravel administration panel

1.3k268.2k89](/packages/moonshine-moonshine)[api-platform/laravel

API Platform support for Laravel

58190.1k21](/packages/api-platform-laravel)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5226.7k](/packages/simplestats-io-laravel-client)

PHPackages © 2026

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