PHPackages                             bycedric/delegator - 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. bycedric/delegator

AbandonedArchivedLibrary[API Development](/categories/api)

bycedric/delegator
==================

A nice API helper, for Laravel, to keep your responses RESTed.

626PHP

Since Mar 22Pushed 11y ago1 watchersCompare

[ Source](https://github.com/byCedric/Delegator)[ Packagist](https://packagist.org/packages/bycedric/delegator)[ RSS](/packages/bycedric-delegator/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Delegator
=========

[](#delegator)

A nice API helper, for Laravel, to keep your responses RESTed. It blends in with the usual Response of Laravel.

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

[](#installation)

You can install this package through Composer.

```
"require-dev": {
    "by-cedric/delegator": "dev-master"
}
```

Delegator extends the basic Response facade of Laravel. So you need to use the Delegator's version of the Response facade. Ofcourse you can still use the standard functions of Response.

In your config/app.php search for this line:

```
'aliases' => array(
    ...
    'Response'        => 'Illuminate\Support\Facades\Response',
    ...
)
```

And replace it with:

```
'aliases' => array(
    ...
    'Response'        => 'ByCedric\Delegator\Facades\Response',
    ...
)
```

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

[](#basic-usage)

You can use Delegator as simple as:

```
Response::api();
```

This initiates a new Delegator, that is actually a Response object. So when you are done setting your response, you can just return it as a normal response:

```
public function show( $id )
{
    $task = Task::find($id);

    return Response::api($task);
}
```

Functions
---------

[](#functions)

All functions are chainable. A new Delegator instance is created using the Response facade:

```
Response::api();
```

You can use one of the following functions, as chained methods, to manipulate the response.

### code

[](#code)

Within a normal response, there is always a status code to explain the basic situation.

It accepts an integer.

```
Response::api()->code(403);
```

### message

[](#message)

An API response is often read by developers, when developing their application. During the development process, a lot can go wrong. So it is always recomended to provide a human readable message.

It accepts a string.

```
Response::api()->message('Please specify a valid API key.');
```

### data

[](#data)

An API response is almost all the time filled with data. No need for explaination I think...

It accepts an array, or any object that implements the ArrayableInterface.

```
Response::api()->data($task);
```

Note that the constructor of the Delegator also accepts data, exactly the same way.

```
Response::api($task);
```

### callback

[](#callback)

Not all the time a simple JSON request can be made. Then you will just have to use the JSONP response.

It accepts a string.

```
Response::api()->callback('loaded_call');
```

### error

[](#error)

When an error occures, you probably want it responded asap. The error takes care of the human readable message and the http status code.

It accepts a string and integer.

```
Response::api()->error('Could not find task with id #'. $id, 404);
```

### limit

[](#limit)

When responding with a collection, info about the amount of items that can be returned at once is very useful. For example, you can build your pagination with it.

It accepts an integer, or boolean to remove any set value.

```
Response::api()->limit(100);
```

### offset

[](#offset)

When responding with a collection, info about the current offset of the total collection is very useful. For example, you can build your pagination with it.

```
Response::api()->offset(45);
```

### count

[](#count)

When responding with a collection, info about the total amount of items in existence is very useful. For example, you can build your pagination with it.

```
Response::api()->count(231);
```

### mockCode

[](#mockcode)

Some (old) clients are very clumsy with errors in the http status code. When this is the case, it is best to let the client relax for a bit. This will always pass http status code 200, only the code within the response is the real one.

It accepts a boolean, mostly used to disable it again.

```
Response::api()->code(404)->mockCode();
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/8f4ce064b5be71889d8571b5e3f9ef66a3c3cace0361966690abd00930b5be7d?d=identicon)[byCedric](/maintainers/byCedric)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/bycedric-delegator/health.svg)

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

###  Alternatives

[exsyst/swagger

A php library to manipulate Swagger specifications

35816.3M7](/packages/exsyst-swagger)[hubspot/api-client

Hubspot API client

24015.5M18](/packages/hubspot-api-client)[pocketmine/bedrock-protocol

An implementation of the Minecraft: Bedrock Edition protocol in PHP

172437.8k11](/packages/pocketmine-bedrock-protocol)[botman/driver-telegram

Telegram driver for BotMan

94452.6k6](/packages/botman-driver-telegram)

PHPackages © 2026

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