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

ActiveLibrary[API Development](/categories/api)

signaturetech/laravel-api-response-builder
==========================================

A super simple package allowing for consistent API responses throughout your Laravel application

1.0.3(8mo ago)143722MITPHPPHP &gt;=8.0CI failing

Since May 25Pushed 8mo ago1 watchersCompare

[ Source](https://github.com/SignatureTech/laravel-api-response-builder)[ Packagist](https://packagist.org/packages/signaturetech/laravel-api-response-builder)[ RSS](/packages/signaturetech-laravel-api-response-builder/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (3)Versions (5)Used By (0)

[![Laravel](https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg)](https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg)

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

[](#laravel-api-response-builder)

---

[![GitHub](https://camo.githubusercontent.com/38b219bfb34b31d3c9ed0debeada17cb94c057cb4262f4d8f0730a494ac94148/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7369676e6174757265746563682f6c61726176656c2d6170692d726573706f6e73652d6275696c646572)](https://camo.githubusercontent.com/38b219bfb34b31d3c9ed0debeada17cb94c057cb4262f4d8f0730a494ac94148/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f7369676e6174757265746563682f6c61726176656c2d6170692d726573706f6e73652d6275696c646572)[![Unit Tests](https://github.com/signaturetech/laravel-api-response-builder/actions/workflows/phpunit.yml/badge.svg)](https://github.com/signaturetech/laravel-api-response-builder/actions/workflows/phpunit.yml)[![Packagist Downloads](https://camo.githubusercontent.com/d77a6eac8ce3d3967dea37f99ecfb503b8c18b706ebc51dc840083c64f0c2651/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7369676e6174757265746563682f6c61726176656c2d6170692d726573706f6e73652d6275696c646572)](https://camo.githubusercontent.com/d77a6eac8ce3d3967dea37f99ecfb503b8c18b706ebc51dc840083c64f0c2651/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7369676e6174757265746563682f6c61726176656c2d6170692d726573706f6e73652d6275696c646572)

Table of contents
-----------------

[](#table-of-contents)

- [Introduction](#introduction)
- [Installation &amp; Configuration](#installation--configuration)
- [Examples](#examples)
- [License](#license)

Introduction
------------

[](#introduction)

`ResponseBuilder` is a [Laravel](https://laravel.com/) package, designed to help you build a nice, normalized and easy to consume REST API JSON responses.

Installation &amp; Configuration
--------------------------------

[](#installation--configuration)

You can install this package via composer using:

```
composer require signaturetech/laravel-api-response-builder

```

Next run the command below to setup `api-response.config` file, you can set your configuration.

```
php artisan vendor:publish --tag=response-builder

```

Examples
--------

[](#examples)

### Example : Success

[](#example--success)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function index() {
    $users = User::query()->take(2)->get();

    return ResponseBuilder::success($users);
}

// Output
Status: 200 OK
{
    "status": true,
    "data": [
        {
            "id": 1,
            "name": "Prof. Bell Hayes",
            "email": "myundt@example.net",
            "email_verified_at": "2022-12-07T05:27:30.000000Z",
            "created_at": "2022-12-07T05:27:30.000000Z",
            "updated_at": "2022-12-07T05:27:30.000000Z"
        },
        {
            "id": 2,
            "name": "Ms. Tessie Streich III",
            "email": "dledner@example.net",
            "email_verified_at": "2022-12-07T05:27:30.000000Z",
            "created_at": "2022-12-07T05:27:30.000000Z",
            "updated_at": "2022-12-07T05:27:30.000000Z"
        }
    ]
}

```

### Example : Custom Success

[](#example--custom-success)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function login() {
    $user = User::query()->first();
    $token = Uuid::uuid4();

    return ResponseBuilder::asSuccess()
        ->withMessage('Successfuly Login')
        ->with('auth_token', $token)
        ->withData([
            'profile' => new UserResource($user)
        ])
        ->build();
}

// Output
Status: 200 OK
{
    "status": true,
    "message": "Successfuly Login",
    "auth_token": "65050859-1a05-4fa8-827f-7023ff73d4a3",
    "data": {
        "profile": {
            "id": 1,
            "name": "Prof. Bell Hayes",
            "email": "myundt@example.net"
        }
    }
}

```

### Example : Error

[](#example--error)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function index() {
    return ResponseBuilder::error('Sorry We are not able to getting your details', Response::HTTP_INTERNAL_SERVER_ERROR);
}

// Output
Status: 500 Internal Server Error
{
    "status": false,
    "message": "Sorry We are not able to getting your details"
}

```

### Example : Custom Error

[](#example--custom-error)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function index() {
    return ResponseBuilder::asError(Response::HTTP_BAD_GATEWAY)
        ->withMessage('Sorry We are not able to getting your details')
        ->with('custom_key', 'value')
        ->withData([
            'bad_gateway_error' => 'We are not able to process your request'
        ])
        ->build();
}

// Output
Status: 502 Bad Gateway
{
    "status": false,
    "message": "Sorry We are not able to getting your details",
    "code": 10001,
    "data": {
        "bad_gateway_error": "We are not able to process your request"
    }
}

```

### Example : Validation Error Message

[](#example--validation-error-message)

```
use SignatureTech\ResponseBuilder\Http\ValidationFailed;

class UserRequest extends FormRequest
{
    use ValidationFailed;

    .
    .
}

// Output
Status: 400 Bad Request
{
    "status": false,
    "errors": {
        "name": [
            "The name field is required."
        ],
        "email": [
            "The email field is required."
        ]
    }
}

```

- You can customize HttpStatus Code in `config/api-response.php` under the variable `validation_http_code`.
- You can customize your error message `config/api-response.php` under the variable `show_validation_failed_message`, `all` for get all error messages and `first` for get the first message.

Example:

```
// config/api-response.php
'show_validation_failed_message'  => 'first',

// Output
Status: 400 Bad Request
{
    "status": false,
    "message": "The name field is required."
}

```

### Example : Custom Filed

[](#example--custom-filed)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function index() {
    $user = User::query()->first();

    $token = Uuid::uuid4();

    return ResponseBuilder::asSuccess()->with('auth_token', $token)->withData($user)->build();
}

// Output:
Status: 200 OK
{
    "status": true,
    "auth_token": "21d97007-e2b9-4ee1-86b1-3cfb96787436",
    "data": {
        "id": 1,
        "name": "Prof. Bell Hayes",
        "email": "myundt@example.net",
        "email_verified_at": "2022-12-07T05:27:30.000000Z",
        "created_at": "2022-12-07T05:27:30.000000Z",
        "updated_at": "2022-12-07T05:27:30.000000Z"
    }
}

```

### Example : Pagination

[](#example--pagination)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function index() {
    $user = User::query()->paginate(3);

    return ResponseBuilder::asSuccess()->withPagination($user)->build();
}

// Output:
Status: 200 OK
{
    "status": true,
    "data": [
        {
            "id": 1,
            "name": "Prof. Bell Hayes",
            "email": "myundt@example.net",
            "email_verified_at": "2022-12-07T05:27:30.000000Z",
            "created_at": "2022-12-07T05:27:30.000000Z",
            "updated_at": "2022-12-07T05:27:30.000000Z"
        },
        .
        .
    ],
    "meta": {
        "total_page": 14,
        "current_page": 1,
        "total_item": 40,
        "per_page": 3
    },
    "link": {
        "next": true,
        "prev": false
    }
}

```

### Example : Pagination and you are using JsonResource

[](#example--pagination-and-you-are-using-jsonresource)

```
use SignatureTech\ResponseBuilder\ResponseBuilder;

public function index() {
    $user = User::query()->paginate(3);

    return ResponseBuilder::asSuccess()->withPagination($user, UserResource::class)->build();
}

// Output:
Status: 200 OK
{
    "status": true,
    "data": [
        {
            "id": 1,
            "name": "Prof. Bell Hayes",
            "email": "myundt@example.net"
        },
        .
        .
    ],
    "meta": {
        "total_page": 14,
        "current_page": 1,
        "total_item": 40,
        "per_page": 3
    },
    "link": {
        "next": true,
        "prev": false
    }
}

```

License
-------

[](#license)

- Written and copyrighted ©2022 by Prem Chand Saini ()
- ResponseBuilder is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance60

Regular maintenance activity

Popularity23

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

4

Last Release

257d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bf4d0865340d72f2c8d8aa8f9cdfde716e84013fdcf87d50318562ac92fcb2e9?d=identicon)[pcsaini](/maintainers/pcsaini)

---

Top Contributors

[![pcsaini](https://avatars.githubusercontent.com/u/10773104?v=4)](https://github.com/pcsaini "pcsaini (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[echolabsdev/prism

A powerful Laravel package for integrating Large Language Models (LLMs) into your applications.

2.3k388.3k10](/packages/echolabsdev-prism)[sburina/laravel-whmcs-up

WHMCS API client and user provider for Laravel

271.3k](/packages/sburina-laravel-whmcs-up)

PHPackages © 2026

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