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 10y ago1 watchersCompare

[ Source](https://github.com/byCedric/Delegator)[ Packagist](https://packagist.org/packages/bycedric/delegator)[ RSS](/packages/bycedric-delegator/feed)WikiDiscussions master Synced 2d 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 27% 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

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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