PHPackages                             chhw/api-response - 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. chhw/api-response

ActiveLibrary[API Development](/categories/api)

chhw/api-response
=================

This package gives you an easier way to return RESTful API response.

1.3.0(4y ago)131MITPHPPHP &gt;=5.4

Since Jul 25Pushed 4y agoCompare

[ Source](https://github.com/wangchristine/api-response)[ Packagist](https://packagist.org/packages/chhw/api-response)[ RSS](/packages/chhw-api-response/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (3)Versions (12)Used By (0)

Laravel Api Response
====================

[](#laravel-api-response)

> This package gives you an easier way to return RESTful API response.

Installation
============

[](#installation)

Install by composer

```
    $ composer require chhw/api-response
```

If you are under Laravel 5.5, please add this code in `config/app.php` below.

```

```

\[Option\] Get response config to customize debug message.

```
    $ php artisan vendor:publish --provider="CHHW\ApiResponse\ApiResponseServiceProvider"
```

Also support Lumen now!!
------------------------

[](#also-support-lumen-now)

In `bootstrap/app.php`, you should:

1. add `$app->register(CHHW\ApiResponse\ApiResponseServiceProvider::class);`

\[Option\] Get response config to customize debug message.

```
    $ cp vendor/chhw/api-response/src/config/response.php config/response.php
```

Usage
=====

[](#usage)

> Should be used in your controller.

### Define:

[](#define)

You can choose what you prefer:

1. construct: `$this->response = new ApiResponse`
2. injection: `ApiResponse $response`

### Example:

[](#example)

> General

```
 // You can set header and option in construct.
$this->response->setHeader(["lang" => "en"])->setOption(JSON_UNESCAPED_UNICODE);

// Basic usage.
return $this->response->success([1, 2])->json();
return $this->response->error("Oh no")->json();

// Custom status and code.
return $this->response->success([1, 2], 201, "code201")->json();
return $this->response->error("Oh no", 501, "code501")->json();
```

> Inline

```
return $this->response->success([1, 2])->setHeader(["lang" => "en"])->setOption(JSON_UNESCAPED_UNICODE)->json();
return $this->response->error("Oh no", 501, "code501")->setHeader(["lang" => "en"])->setOption(JSON_UNESCAPED_UNICODE)->json();
```

### \[Option\] Custom debug message:

[](#option-custom-debug-message)

If you have custom code, by default it will match `config/response.php` settings for debug message:

```
// Controller
return $this->response->error([1, 2], 500, 'custom500')->json();

// config/response.php
return [
    'code' => [
        'custom500' => 'Internal Server Error',
    ]
];
```

### Response:

[](#response)

> Success

```
 {
    "success": true,
    "detail": {
        "status": 200,
        "code": "200",
        "message": "OK"
    },
    "data": {
        ...
    },
    "link": null,
    "meta": null
 }
```

> Error

```
 {
    "success": false,
    "detail": {
        "status": 404,
        "code": "404",
        "message": "Something went wrong."
    },
    "error": {
        ...
    },
    "link": null,
    "meta": null
 }
```

Supported methods
=================

[](#supported-methods)

> $data can be array, string or object etc.

> $code for someone who want to custom internal http code.

```
public function success($data = [], $status = 200, $code = "200");
public function error($data = [], $status = 500, $code = "500");
public function setHeader($headers);
public function setOption($options);
```

Log tracing
===========

[](#log-tracing)

> Response header with an unique UUID4: `X-Trace-Id`

Collection Paginator
====================

[](#collection-paginator)

> Collection Paginator usage just like model !

> You can use Api Response and Collection Paginator together.

### Example:

[](#example-1)

```
collect([1,2,3,4,5])->paginate(10)
collect([1,2,3,4,5])->simplePaginate(15)
```

### Supported methods:

[](#supported-methods-1)

```
paginate($perPage = 15, $pageName = 'page', $page = null);
simplePaginate($perPage = 15, $pageName = 'page', $page = null);
```

###  Health Score

26

—

LowBetter than 41% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

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

Every ~54 days

Recently: every ~132 days

Total

11

Last Release

1625d ago

PHP version history (3 changes)1.0.1PHP ^7.0.0

1.0.2PHP ^5.4

1.0.4PHP &gt;=5.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13899296?v=4)[wangchristine](/maintainers/wangchristine)[@wangchristine](https://github.com/wangchristine)

---

Top Contributors

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

---

Tags

laravelresponserestful-apiresponseapilaravellumenrestful

### Embed Badge

![Health badge](/badges/chhw-api-response/health.svg)

```
[![Health](https://phpackages.com/badges/chhw-api-response/health.svg)](https://phpackages.com/packages/chhw-api-response)
```

###  Alternatives

[laravel/horizon

Dashboard and code-driven configuration for Laravel queues.

4.2k95.4M306](/packages/laravel-horizon)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[flugger/laravel-responder

A Laravel Fractal package for building API responses, giving you the power of Fractal and the elegancy of Laravel.

8911.6M5](/packages/flugger-laravel-responder)[directorytree/ldaprecord-laravel

LDAP Authentication &amp; Management for Laravel.

5752.3M18](/packages/directorytree-ldaprecord-laravel)

PHPackages © 2026

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