PHPackages                             laurynasgadl/restponder-php - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. laurynasgadl/restponder-php

ActiveLibrary[HTTP &amp; Networking](/categories/http)

laurynasgadl/restponder-php
===========================

REST API response data builder

1.0.0(5y ago)316MITPHPPHP &gt;=7.3

Since Oct 29Pushed 5y ago1 watchersCompare

[ Source](https://github.com/laurynasgadl/restponder-php)[ Packagist](https://packagist.org/packages/laurynasgadl/restponder-php)[ RSS](/packages/laurynasgadl-restponder-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (2)Used By (0)

Restponder
==========

[](#restponder)

Build a better REST API response.

Response examples
-----------------

[](#response-examples)

#### Successful

[](#successful)

```
use Luur\Restponder\Restponder;

$response = Restponder::content('happy little 🌳');
```

```
{
    "success":true,
    "result":"happy little \ud83c\udf33",
    "error":null
}
```

#### Successful with attached metadata

[](#successful-with-attached-metadata)

```
use Luur\Restponder\Restponder;

$response = Restponder::content('happy little 🌳');
$response->addMetadata('request_id', '1234-5678');
```

```
{
    "success":true,
    "result":"happy little \ud83c\udf33",
    "error":null,
    "metadata":{
        "request_id":"1234-5678"
    }
}
```

#### Failed

[](#failed)

```
use Luur\Restponder\Restponder;

$response = Restponder::content(new Exception('Oops', 987));
```

```
{
    "success":false,
    "result":null,
    "error":{
        "code":987,
        "message":"Oops"
    }
}
```

#### Failed with debug included

[](#failed-with-debug-included)

```
use Luur\Restponder\Restponder;

Restponder::setErrorIncludeDebug(true);
$response = Restponder::content(new Exception('Oops', 987));
```

```
{
    "success":false,
    "result":null,
    "error":{
        "code":987,
        "message":"Oops",
        "debug":{
            "type":"Exception",
            "trace":"#0 ..."
        }
    }
}
```

#### Failed with attached details

[](#failed-with-attached-details)

```
use Luur\Restponder\ErrorData;
use Luur\Restponder\Restponder;

$handler = function (Exception $exception, ErrorData $data) {
    $data->addDetail('is_validation_exception', $exception instanceof ValidationException);
};

Restponder::registerErrorHandler(Exception::class, $handler);
$response = Restponder::content(new Exception('Oops', 987));
```

```
{
    "success":false,
    "result":null,
    "error":{
        "code":0,
        "message":"Unexpected error occurred",
        "details":{
            "is_validation_exception":false
        }
    }
}
```

Usage
-----

[](#usage)

### Response data

[](#response-data)

#### Custom object handler

[](#custom-object-handler)

You can register a custom object handler, to be able to parse response data from any kind of object, however you like.

```
use Luur\Restponder\ResponseContent;
use Luur\Restponder\Restponder;

$handler = function (Exception $exception, ResponseContent $response) {
    $response->addMetadata('failed', true);
    $response->addMetadata('error_message', $exception->getMessage());
};

Restponder::registerResponseHandler(Exception::class, $handler);
```

### Error data

[](#error-data)

#### Custom object handler

[](#custom-object-handler-1)

You can register a custom object handler, just like with `Response`.

```
use Luur\Restponder\ErrorData;
use Luur\Restponder\Restponder;

$handler = function (Exception $exception, ErrorData $data) {
    $data->setMessage($exception->getCode().$exception->getMessage());
    $data->addDetail('test', true);
};

Restponder::registerErrorHandler(Exception::class, $handler);
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

2020d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/96be8579ec0431ecc7a87ea091e9eaf1a45d8c662c6b12d1338bd05b21cb964f?d=identicon)[laurynasgadl](/maintainers/laurynasgadl)

---

Top Contributors

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

---

Tags

responsephpapirestbuilder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/laurynasgadl-restponder-php/health.svg)

```
[![Health](https://phpackages.com/badges/laurynasgadl-restponder-php/health.svg)](https://phpackages.com/packages/laurynasgadl-restponder-php)
```

###  Alternatives

[marcin-orlowski/laravel-api-response-builder

Helps building nice, normalized and easy to consume Laravel REST API.

837458.6k3](/packages/marcin-orlowski-laravel-api-response-builder)[huaweicloud/huaweicloud-sdk-php

Huawei Cloud SDK for PHP

1829.2k2](/packages/huaweicloud-huaweicloud-sdk-php)

PHPackages © 2026

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