PHPackages                             emyoutis/laravel-whitehouse-responder - 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. emyoutis/laravel-whitehouse-responder

ActiveLibrary[API Development](/categories/api)

emyoutis/laravel-whitehouse-responder
=====================================

A simple API for generating responses in WhiteHouse standards in Laravel.

1.1.0(6y ago)141.8k1MITPHP

Since Jun 6Pushed 6y agoCompare

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

READMEChangelog (2)Dependencies (2)Versions (4)Used By (1)

WhiteHouse Responder
====================

[](#whitehouse-responder)

This package provides some tools to generate API responses based on the [White House Standards](https://github.com/WhiteHouse/api-standards) in Laravel.

💡 In this package, [this PHP package](https://github.com/emyoutis/whitehouse-responder) is being used.

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

[](#installation)

```
$ composer require emyoutis/laravel-whitehouse-responder

```

Usage
-----

[](#usage)

The bellow aliases are being registered in the main service provider of this package.

- `WhiteHouseResponderResponse` for `Emyoutis\LaravelWhiteHouseResponder\Facades\Response`
- `WhiteHouseResponderErrors` for `Emyoutis\LaravelWhiteHouseResponder\Facades\ErrorsRepository`

In all the examples below, the aliases are being used instead of the full namespaces.

### Registering Errors

[](#registering-errors)

Based on the White House Standards, every error code should points to an error entity. In the WhiteHouse Responder, you can register your errors and their information in an ErrorsRepository class to use them after that.

```
WhiteHouseResponderErrors::register(
     '40001',
     'Verbose, plain language description of the problem. Provide developers suggestions about how to solve their problems here',
     'This is a message that can be passed along to end-users, if needed.',
     'http://www.example.gov/developer/path/to/help/for/444444'
);
```

### Unregistering Errors

[](#unregistering-errors)

It is a common problem that you need to unregister an error after registering it. You can do that with the code below.

```
WhiteHouseResponderErrors::unregister('40001');
```

### Making Failure Responses

[](#making-failure-responses)

Given that in the White House Standards failure responses should return `400` or `500` responses. So that the we have two usable methods to return errors with these statuses.

- `clientError()`: This method is ready to generate the response body for the client errors. ```
    WhiteHouseResponderResponse::clientError('40001');
    ```
- `serverError()`: This method is ready to generate the response body for the server errors. ```
    WhiteHouseResponderResponse::serverError('40001');
    ```

After that, we also have another method to be used when you want to specify the status manually.

```
WhiteHouseResponderResponse::error('40001', 422);
```

#### Replacements

[](#replacements)

You can place some replaceable phrases in the errors info while registering it, to make their contents dynamic. The replaceable phrases should start with a `:`.

```
WhiteHouseResponderErrors::register(
     '40001',
     'The class `:class` is undefined.',
     'An error has been occurred in while finding the :entity.',
     'http://www.example.gov/developer/path/to/help/for/444444'
);

return WhiteHouseResponderResponse::clientError(40001, [
     'class'  => 'Entities/User',
     'entity' => 'user',
])
```

The returning value will be:

```
{
  "status": 400,
  "developerMessage": "The class `Entities/User` is undefined.",
  "userMessage": "An error has been occurred in while finding the user.",
  "errorCode": "40001",
  "moreInfo": "http://www.example.gov/developer/path/to/help/for/444444"
}
```

#### Omitting Error Exception

[](#omitting-error-exception)

By default, the errors repository throws exceptions on registering a previously registered error code and requesting for a non-existing error code. But you can disable throwing these exceptions with the code below.

```
WhiteHouseResponderErrors::disableExceptions();
```

### Making Success Responses

[](#making-success-responses)

As the White House Standards says, the success responses must contain two parts; `results` and `metadata`. These parts can be passed to a `success()` method to generate a success response.

```
$results  = [
     [
          'id'    => 1,
          'title' => 'First Item',
     ],
     [
          'id'    => 2,
          'title' => 'Second Item',
     ],
];
$metadata = ['page' => 1];

$response = WhiteHouseResponderResponse::success($results, $metadata);
```

### Key Formatter

[](#key-formatter)

You can register a closure to be used to format all the keys which are being generated by the package. For example, if we have a `snake_case()` function to map strings to the snake-case format, we can use the below code.

```
WhiteHouseResponderErrors::register(
     '40001',
     'Verbose, plain language description of the problem. Provide developers suggestions about how to solve their problems here',
     'This is a message that can be passed along to end-users, if needed.',
     'http://www.example.gov/developer/path/to/help/for/444444'
);

WhiteHouseResponderErrors::registerFormatter(function ($key) {
    return snake_case($key);
});

return WhiteHouseResponderErrors::clientError(40001);
```

The returning result of this code will be:

```
{
  "status": 400,
  "developer_message": "Verbose, plain language description of the problem. Provide developers suggestions about how to solve their problems here",
  "user_message": "This is a message that can be passed along to end-users, if needed.",
  "error_code": "40001",
  "more_info": "http://www.example.gov/developer/path/to/help/for/444444"
}

```

💡 Changing the keys may take your responses out of the WhiteHouse Standards.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity22

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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

Total

2

Last Release

2403d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/579077f62f5c8f94ee2ee51cd5bc3f1ac930507ec617b0f6be9f525e037e89fd?d=identicon)[emyoutis](/maintainers/emyoutis)

---

Top Contributors

[![emyoutis](https://avatars.githubusercontent.com/u/10210082?v=4)](https://github.com/emyoutis "emyoutis (15 commits)")

---

Tags

apiapi-responderapi-responseapi-restlaravelphpwhitehouseapilaravelWhiteHouse

### Embed Badge

![Health badge](/badges/emyoutis-laravel-whitehouse-responder/health.svg)

```
[![Health](https://phpackages.com/badges/emyoutis-laravel-whitehouse-responder/health.svg)](https://phpackages.com/packages/emyoutis-laravel-whitehouse-responder)
```

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[nickurt/laravel-postcodeapi

Universal PostcodeApi for Laravel 11.x/12.x/13.x

97221.2k](/packages/nickurt-laravel-postcodeapi)[mozex/anthropic-laravel

Anthropic PHP for Laravel is a supercharged PHP API client that allows you to interact with the Anthropic API

71226.4k1](/packages/mozex-anthropic-laravel)

PHPackages © 2026

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