PHPackages                             nathanmac/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. nathanmac/responder

ActiveLibrary[API Development](/categories/api)

nathanmac/responder
===================

Simple PHP Responder Utility Library for API Development

v2.1(9y ago)42454[1 PRs](https://github.com/nathanmac/Responder/pulls)MITPHPPHP &gt;=5.3.0

Since Jun 4Pushed 7y ago2 watchersCompare

[ Source](https://github.com/nathanmac/Responder)[ Packagist](https://packagist.org/packages/nathanmac/responder)[ Docs](https://github.com/nathanmac/Responder)[ RSS](/packages/nathanmac-responder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (6)Used By (0)

Responder
=========

[](#responder)

[![Build Status](https://camo.githubusercontent.com/0f5478868b3e85f40fa513d2fa0d5afec679b0aae92c046a3b8cd2e7d9f7c8b7/68747470733a2f2f7472617669732d63692e6f72672f6e617468616e6d61632f526573706f6e6465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/nathanmac/Responder)[![License](https://camo.githubusercontent.com/9bac02bc6729ed189caa5e6f12260e25691156020c5a4ca74582428d6e510fab/687474703a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6e617468616e6d61632f526573706f6e6465722e737667)](https://github.com/nathanmac/Responder/blob/master/LICENSE.md)[![Code Climate](https://camo.githubusercontent.com/9089a713939d72a8a721f901f7f9c28735b35ed07ffb1fd2c11861bbe0d46123/68747470733a2f2f636f6465636c696d6174652e636f6d2f6769746875622f6e617468616e6d61632f526573706f6e6465722e706e67)](https://codeclimate.com/github/nathanmac/Responder)[![Coverage Status](https://camo.githubusercontent.com/80cc354054409f813be3a115f0260e4f324e5f08d7f3a61f7aafdcc4886faf0d/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6e617468616e6d61632f526573706f6e6465722f62616467652e706e67)](https://coveralls.io/r/nathanmac/Responder)[![Latest Stable Version](https://camo.githubusercontent.com/44db2677471c137d6e81d42a2366e4dfa3ecc9daa0b0fc3772827f6875d46640/68747470733a2f2f706f7365722e707567782e6f72672f6e617468616e6d61632f726573706f6e6465722f762f737461626c652e737667)](https://packagist.org/packages/nathanmac/responder)[![SensioLabsInsight](https://camo.githubusercontent.com/8a30d2503a4bf1fae6be35b8b9fc16d794fbbc52ae627bab8955c6982b5623b6/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f31306631353035622d633438662d343032302d613736322d3935643736383538323062652f6d696e692e706e67)](https://insight.sensiolabs.com/projects/10f1505b-c48f-4020-a762-95d7685820be)

Simple PHP Responder Utility Library for API Development

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

[](#installation)

Begin by installing this package through Composer. Edit your project's `composer.json` file to require `Nathanmac/Responder`.

```
"require": {
	"Nathanmac/Responder": "2.*"
}

```

Next, update Composer from the Terminal:

```
composer update

```

### Laravel Users

[](#laravel-users)

If you are a Laravel user, then there is a service provider that you can make use of to automatically prepare the bindings and such.

```
// app/config/app.php

'providers' => [
    '...',
    'Nathanmac\Utilities\Responder\ResponderServiceProvider'
];
```

When this provider is booted, you'll have access to a helpful `Responder` facade, which you may use in your controllers.

```
public function index()
{
    Responder::json($payload);         // Array > JSON
    Responder::xml($payload);          // Array > XML
    Responder::yaml($payload);         // Array > YAML
    Responder::querystr($payload);     // Array > Query String
    Responder::serialize($payload);    // Array > Serialized Object
    Responder::bson($payload);         // Array > BSON
    Responder::msgpack($payload);      // Array > MessagePack
}
```

#### Responder Functions

[](#responder-functions)

```
$responder->json($payload);         // Array > JSON
$responder->xml($payload);          // Array > XML
$responder->yaml($payload);         // Array > YAML
$responder->querystr($payload);     // Array > Query String
$responder->serialize($payload);    // Array > Serialized Object
$responder->bson($payload);         // Array > BSON
$responder->msgpack($payload);      // Array > MessagePack
```

#### Respond with Automatic Detection

[](#respond-with-automatic-detection)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header("Content-Type: {$responder->getContentType()}");
print $responder->payload($body);
```

#### Respond with JSON

[](#respond-with-json)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header('Content-Type: application/json');
print $responder->json($body);
```

#### Respond with XML

[](#respond-with-xml)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header('Content-Type: application/xml; charset=utf-8');
print $responder->xml($body);
```

#### Respond with Query String

[](#respond-with-query-string)

```
$responder = new Responder();

$body = array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
);

header('Content-Type: application/x-www-form-urlencoded');
print $responder->querystr($body);
```

#### Respond with Serialized Object

[](#respond-with-serialized-object)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header('Content-Type: application/vnd.php.serialized');
print $responder->serialize($body);
```

#### Respond with YAML

[](#respond-with-yaml)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header('Content-Type: application/x-yaml');
print $responder->yaml($body);
```

#### Respond with BSON

[](#respond-with-bson)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header('Content-Type: application/bson');
print $responder->bson($body);
```

#### Respond with MessagePack

[](#respond-with-messagepack)

```
$responder = new Responder();

$body = array(
    'message' => array(
        'to' => 'Jack Smith',
        'from' => 'Jane Doe',
        'subject' => 'Hello World',
        'body' => 'Hello, whats going on...'
    )
);

header('Content-Type: application/x-msgpack');
print $responder->msgpack($body);
```

Custom Responders/Formatters
----------------------------

[](#custom-respondersformatters)

You can make your own custom responders/formatters by implementing [FormatInterface](https://github.com/nathanmac/Responder/blob/master/src/Formats/FormatInterface.php), the below example demostrates the use of a custom responder/formatter.

```
use Nathanmac\Utilities\Responder\Formats\FormatInterface;

/**
 * Custom Formatter
 */

class CustomFormatter implements FormatInterface {
    /**
     * Generate Payload Data
     *
     * @param array $payload
     *
     * @return string
     *
     * @throws ResponderException
     */
    public function generate($payload)
    {
        $payload; // Raw payload array

        $output = // Process raw payload array to formatted data

        return $output; // return data string
    }
}
```

##### Using the CustomFormatter

[](#using-the-customformatter)

```
use Acme\Formatters\CustomFormatter;

$responder = new Responder();
$generated = $responder->generate(['raw' => 'payload', 'data'], new CustomFormatter());
```

##### Register the CustomFormatter

[](#register-the-customformatter)

```
use Acme\Formatters\CustomFormatter;

$responder = new Responder();
$responder->registerFormat('application/x-custom-format', 'Acme\Formatters\CustomFormatter');
$responder->payload('application/x-custom-format');
```

Testing
-------

[](#testing)

To test the library itself, run the PHPUnit tests:

```
phpunit tests/

```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 90.9% 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 ~196 days

Total

5

Last Release

3582d ago

Major Versions

v1.2 → v2.02014-10-27

PHP version history (2 changes)v1.0PHP &gt;=5.2.0

v2.1PHP &gt;=5.3.0

### Community

Maintainers

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

---

Top Contributors

[![nathanmac](https://avatars.githubusercontent.com/u/3205902?v=4)](https://github.com/nathanmac "nathanmac (10 commits)")[![danhunsaker](https://avatars.githubusercontent.com/u/1534396?v=4)](https://github.com/danhunsaker "danhunsaker (1 commits)")

---

Tags

jsonformatterapixmlresponder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nathanmac-responder/health.svg)

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

###  Alternatives

[nathanmac/parser

Simple PHP Parser Utility Library for API Development

2151.0M3](/packages/nathanmac-parser)[nilportugues/api-problems

PSR7 Response implementation for the Problem Details for HTTP APIs

1749.4k2](/packages/nilportugues-api-problems)[walle89/swedbank-json

Unofficial API client for the Swedbank's and Sparbanken's mobile apps in Sweden.

752.5k](/packages/walle89-swedbank-json)

PHPackages © 2026

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