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.

0.1.0(3mo ago)19↓50%MITPHPPHP ^8.2CI passing

Since Jan 21Pushed 3mo 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 main Synced 1mo ago

READMEChangelog (1)Dependencies (7)Versions (2)Used By (0)

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

[](#laravel-api-response)

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

#### What this package is

[](#what-this-package-is)

- a small abstraction over JSON responses
- a way to standardize API responses across your app
- minimal by default, customizable by design
- IDE-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"
  }
}
```

All keys and values are fully configurable via config or by replacing the payload builder.

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

[](#installation)

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

Optional config publishing:

```
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 index()
    {
        return $this->api->success('OK', [
            'id' => 1,
        ]);
    }
}
```

#### 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

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

$this->app->bind(ApiResponseContract::class, MyCustomApiResponse::class);
```

Replace the payload builder

```
use Sevaske\ApiResponsePayload\Contracts\ApiResponsePayloadContract;

$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

33

—

LowBetter than 75% of packages

Maintenance79

Regular maintenance activity

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

 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

Unknown

Total

1

Last Release

108d ago

### 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 (18 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

[dragon-code/laravel-json-response

Automatically always return a response in JSON format

1118.6k1](/packages/dragon-code-laravel-json-response)[obiefy/api-response

Simple Laravel package to return Json responses.

17324.6k](/packages/obiefy-api-response)[wayofdev/laravel-symfony-serializer

📦 Laravel wrapper around Symfony Serializer.

2113.6k](/packages/wayofdev-laravel-symfony-serializer)[kennedy-osaze/laravel-api-response

Renders consistent HTTP JSON responses for API-based projects

654.5k](/packages/kennedy-osaze-laravel-api-response)[djurovicigoor/larajsonresponse

Laravel API wrapper for returning JSON response.

116.8k](/packages/djurovicigoor-larajsonresponse)

PHPackages © 2026

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