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

ActiveLibrary[API Development](/categories/api)

osama-98/laravel-response-api
=============================

A package for optimizing and unifying the response of laravel API

2.0.1(4mo ago)12486↓79.4%MITPHPPHP ^8.3CI passing

Since May 16Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/osama-98/laravel-response-api)[ Packagist](https://packagist.org/packages/osama-98/laravel-response-api)[ GitHub Sponsors](https://github.com/osama-98)[ RSS](/packages/osama-98-laravel-response-api/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (16)Versions (16)Used By (0)

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

[](#laravel-api-response)

[![Latest Version on Packagist](https://camo.githubusercontent.com/3a6fff8bc190de13a9e63fa0ed64d757455e71bfc15b1dcb6a4692d6df9d9dc6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6f73616d612d39382f6c61726176656c2d726573706f6e73652d6170692e737667)](https://packagist.org/packages/osama-98/laravel-response-api)[![Total Downloads](https://camo.githubusercontent.com/71e29aa562d0959e3b68599876d6f92b57b2ba8d4014e26429631c0fbb94fc58/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6f73616d612d39382f6c61726176656c2d726573706f6e73652d6170692e737667)](https://packagist.org/packages/osama-98/laravel-response-api)[![License](https://camo.githubusercontent.com/398a80d155db5be96a4d23333eea8257cacfa894801326a1651e8f10911042f0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6f73616d612d39382f6c61726176656c2d726573706f6e73652d6170692e737667)](https://packagist.org/packages/osama-98/laravel-response-api)

A Laravel package that provides a fluent and expressive interface for creating standardized JSON API responses.

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

[](#installation)

You can install the package via composer:

```
composer require osama-98/laravel-response-api
```

Version Compatibility
---------------------

[](#version-compatibility)

PackageLaravelPHP2.x12.x^8.31.x10.x | 11.x^8.1Requirements
------------

[](#requirements)

- PHP ^8.3
- Laravel ^12.0

Response Structure
------------------

[](#response-structure)

All responses follow this standardized JSON structure:

```
{
    "message": "Human-readable message",
    "body": {
        // Response data (optional)
    },
    "errors": {
        // Validation or error details (optional)
    }
}
```

Basic Usage
-----------

[](#basic-usage)

### Success Response

[](#success-response)

```
return ApiResponse::success(
    data: ['user' => $user],
    message: 'User retrieved successfully'
);
```

Response:

```
{
    "message": "User retrieved successfully",
    "body": {
        "user": {
            "id": 1,
            "name": "John Doe",
            "email": "john@example.com"
        }
    }
}
```

### Error Response

[](#error-response)

```
return ApiResponse::error(
    message: 'Validation failed.',
    errors: $validator->errors()->toArray()
);
```

Response:

```
{
    "message": "Validation failed.",
    "errors": {
        "email": [
            "The email field must be a valid email address.",
            "The selected email is invalid."
        ]
    }
}
```

Pagination Support
------------------

[](#pagination-support)

### Using with Resource

[](#using-with-resource)

```
return ApiResponse::pagination(
    paginator: User::paginate(10),
    mapper: UserResource::class
);
```

### Using with Custom Mapper

[](#using-with-custom-mapper)

```
return ApiResponse::pagination(paginator: User::paginate(10), mapper: fn(User $user) => [
    'id' => $user->id,
    'name' => $user->name
]);
```

Fluent Builder
--------------

[](#fluent-builder)

For more complex responses, use the fluent builder:

```
return ApiResponse::builder()
    ->data(['key' => 'value'])
    ->message('Custom message')
    ->errors(['field' => 'error message'])
    ->status(Response::HTTP_BAD_REQUEST)
    ->send();
```

Testing
-------

[](#testing)

```
composer test
```

This runs:

- Code style checks (Laravel Pint)
- Static analysis (PHPStan)
- Unit tests (Pest PHP)
- Type coverage tests

Security
--------

[](#security)

If you discover any security-related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Osama Sadah](https://github.com/osama-98)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 91% of packages

Maintenance78

Regular maintenance activity

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Recently: every ~14 days

Total

15

Last Release

121d ago

Major Versions

1.9.3 → 2.0.02026-03-04

PHP version history (4 changes)1.0.0PHP ^8.3.0

1.3.0PHP ^8.0

1.9.2PHP ^8.1

2.0.0PHP ^8.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/206027dff63d4c1f20eb81d0e556d69ae4afc9406d022df182edcd2818a643ce?d=identicon)[osama.sadah](/maintainers/osama.sadah)

---

Top Contributors

[![osama-98](https://avatars.githubusercontent.com/u/74357061?v=4)](https://github.com/osama-98 "osama-98 (24 commits)")

---

Tags

phplaravelpackagelaravel-apilaravel-response-api

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[joisarjignesh/bigbluebutton

BigBlueButton Server API Library for Laravel

162155.1k1](/packages/joisarjignesh-bigbluebutton)[wayofdev/laravel-symfony-serializer

📦 Laravel wrapper around Symfony Serializer.

2117.7k](/packages/wayofdev-laravel-symfony-serializer)[octw/aramex

A Library to integrate with Aramex APIs

2927.7k](/packages/octw-aramex)[wxm/pdd-sdk

拼多多 SDK 封装, 调用简单、语义化增强。支持 Laravel/Lumen。

154.8k](/packages/wxm-pdd-sdk)

PHPackages © 2026

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