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

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

eozden/api-response
===================

Laravel api response macros

v1.0.3(3y ago)032MITPHP

Since Nov 5Pushed 3y ago1 watchersCompare

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

READMEChangelog (4)Dependencies (2)Versions (7)Used By (0)

Api Response Macros for Laravel
===============================

[](#api-response-macros-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4fc17154a399849ca54cf9b695ab5929cda2bc9f01b52f41f21cf2d30a1303b4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f656f7a64656e2f6170692d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eozden/api-response)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/89b95f42ee5581890a0ded5cce278563b9359995f5cbf9aa7627d6a6f4d566a6/68747470733a2f2f7472617669732d63692e636f6d2f656f7a64656e2f6170692d726573706f6e73652e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/eozden/api-response)[![StyleCI](https://camo.githubusercontent.com/da20c438ec93ed32b417bf07dcad2b2be7d5ecdb7f09dc0d5c9785a320025f3b/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3331303430333739382f736869656c643f6272616e63683d6d6173746572)](https://github.styleci.io/repos/310403798?branch=master)[![Total Downloads](https://camo.githubusercontent.com/a23ce8d118df7fa9ded0228294c8544fae77d403f095f8a99cca93f1a671696d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f656f7a64656e2f6170692d726573706f6e73652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/eozden/api-response)

[![image](https://camo.githubusercontent.com/dec5b8ccebf6c1630e9d913b3d6bd2a4dc6bbdfe5b10840227c4fbc33278d78f/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f415049253230526573706f6e73652e706e673f7468656d653d6c69676874267061636b6167654e616d653d656f7a64656e2532466170692d726573706f6e7365267061747465726e3d617a746563267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b6372656174652b726573742b6170692b726573706f6e736573266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d627269656663617365267769647468733d32303026686569676874733d323030)](https://camo.githubusercontent.com/dec5b8ccebf6c1630e9d913b3d6bd2a4dc6bbdfe5b10840227c4fbc33278d78f/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f415049253230526573706f6e73652e706e673f7468656d653d6c69676874267061636b6167654e616d653d656f7a64656e2532466170692d726573706f6e7365267061747465726e3d617a746563267374796c653d7374796c655f31266465736372697074696f6e3d456173696c792b6372656174652b726573742b6170692b726573706f6e736573266d643d312673686f7757617465726d61726b3d3126666f6e7453697a653d313030707826696d616765733d627269656663617365267769647468733d32303026686569676874733d323030)

This package makes it easy to create rest api responses for Laravel 5.5+, 6.x, 7.x and 8.x.

Contents
--------

[](#contents)

- [Installation](#installation)
- [Usage](#usage)
    - [Available Macros](#available_macros)
    - [Sample Responses](#sample_responses)
    - [Examples](#examples)
    - [Config](#config)
- [Changelog](#changelog)
- [Testing](#testing)
- [Security](#security)
- [Contributing](#contributing)
- [Credits](#credits)
- [License](#license)

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

[](#installation)

Via Composer

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

Or you can manually update your require block and run `composer update` if you choose so:

```
{
    "require": {
        "eozden/api-response": "^1.0"
    }
}
```

Usage
-----

[](#usage)

### Available macros

[](#available-macros)

```
response()->ok($data = null, int $code = null);
response()->error($data = null, int $code = null);
```

### Sample Responses

[](#sample-responses)

```
{
  "success": true,
  "code": 200,
  "locale": "en",
  "message": "OK",
  "data": null
}
```

```
{
  "success": false,
  "code": 422,
  "locale": "en",
  "message": "UNPROCESSABLE ENTITY",
  "data": null
}
```

### Examples

[](#examples)

```
public function delete()
{
    User::find(1)->delete();

    return response()->ok();
}
```

### Config

[](#config)

```
return [

    /**
     * Default response code settings
     */
    "default" => [
        "ok" => \Eozden\ApiResponse\ResponseStatus::OK,
        "error" => \Eozden\ApiResponse\ResponseStatus::UNPROCESSABLE_ENTITY,
    ],

    /**
     * Force to use middleware to return response as a json
     */
    "force" => true,

    /**
     * You can add your custom HTTP Status Codes
     */
    "map" => [
        \Eozden\ApiResponse\ResponseStatus::OK => "ok",
        \Eozden\ApiResponse\ResponseStatus::CREATED => "created",
        \Eozden\ApiResponse\ResponseStatus::ACCEPTED => "accepted",
        \Eozden\ApiResponse\ResponseStatus::NO_CONTENT => "no_content",
        \Eozden\ApiResponse\ResponseStatus::NOT_MODIFIED => "not_modified",
        \Eozden\ApiResponse\ResponseStatus::BAD_REQUEST => "bad_request",
        \Eozden\ApiResponse\ResponseStatus::UNAUTHORIZED => "unauthorized",
        \Eozden\ApiResponse\ResponseStatus::FORBIDDEN => "forbidden",
        \Eozden\ApiResponse\ResponseStatus::NOT_FOUND => "not_found",
        \Eozden\ApiResponse\ResponseStatus::CONFLICT => "conflict",
        \Eozden\ApiResponse\ResponseStatus::UNPROCESSABLE_ENTITY => "unprocessable_entity",
        \Eozden\ApiResponse\ResponseStatus::INTERNAL_SERVER_ERROR => "internal_server_error"
    ]
];
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Enes Özden](https://twitter.com/ensozden)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~263 days

Total

4

Last Release

1229d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1483381?v=4)[Enes Özden](/maintainers/eozden)[@eozden](https://github.com/eozden)

---

Top Contributors

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

---

Tags

responsejsonapilaravelhelperrestbuilderresourcePHP7macro

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  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)[guanguans/laravel-api-response

Normalize and standardize Laravel API response data structure. - 规范化和标准化 Laravel API 响应数据结构。

485.6k](/packages/guanguans-laravel-api-response)

PHPackages © 2026

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