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

ActiveLibrary

mojtabarks/api-response
=======================

A lighweight package to create appropriate response

v2.1.0(4y ago)11321MITPHP

Since Jan 9Pushed 4y ago1 watchersCompare

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

READMEChangelog (4)DependenciesVersions (9)Used By (1)

Laravel / lumen response api
============================

[](#laravel--lumen-response-api)

a lightweight package for create and pass response for use in laravel || lumen

### Prerequisites

[](#prerequisites)

laravel or lumen &gt; v5.4

### Installation

[](#installation)

```
$ composer require mojtabarks/api-response

```

Usage
-----

[](#usage)

you can use Facade or Dependency injection in your project :

Facade Example :
----------------

[](#facade-example-)

```
use Mojtabarks\ApiResponse\ApiResponse;

ApiResponse::successResponse()
    // ->setCode(xxxx)
    // ->setMessage("blah blah blah blah !")
    // ->setSuccessStatus(--boolean !!!--)
    // ->setResponseKey('data')
    // ->setResponseValue(--array-- => [  // --------------> SET DATA METHOD IS ONLY AVAILABLE FOR SUCCESS RESPONSE
        'projectName' => 'my awesome project',
        .
        .
        .
    ])
    ->render();

ApiResponse::failureResponse()
    // ->setCode(xxxx)
    // ->setMessage("blah blah blah blah !")
    // ->setSuccessStatus(--boolean !!!--)
    // ->setResponseKey('error')
    // ->setResponseValue(--array-- => [ // --------------> SET ERROR METHOD IS ONLY AVAILABLE FOR ERROR RESPONSE
        'error text' => 'looks like something went wrong',
        .
        .
        .
    ])
    ->render();

ApiResponse::customResponse()
    // ->setCode(xxxx)
    // ->setMessage("blah blah blah blah !")
    // ->setSuccessStatus(--boolean !!!--)
    // ->setResponseKey('additional')
    // ->setResponseValue(--array-- => [  // --------------> SET ADDITIONAL METHOD IS ONLY AVAILABLE FOR CUSTOM RESPONSE
    //    'custom message' => 'custom message goes here',
    //    .
    //    .
    //    .
    // ])
    ->render();

```

Dependency injection Example :
------------------------------

[](#dependency-injection-example-)

#### 1. first inject your class in constructor

[](#1-first-inject-your-class-in-constructor)

```

use Mojtabarks\ApiResponse\Responses\CustomResponse;
use Mojtabarks\ApiResponse\Responses\SuccessResponse;
use Mojtabarks\ApiResponse\Responses\FailureResponse;

__construct(
    SuccessResponse $successResponse,
    ErrorResponse $errorResponse,
    CustomResponse $customResponse
    ) {
        $this->successResponse
        $this->errorResponse
        $this->customResponse
    }

```

#### 2. use your injected classes wherever you want !

[](#2-use-your-injected-classes-wherever-you-want-)

```

$successResponse = $this->successResponse
    // ->setCode(xxxx)
    // ->setMessage("blah blah blah blah !")
    // ->setSuccessResponse(--boolean !!!--)
    // ->setResponseKey('data')
    // ->setResponseValue(--array-- => [  // --------------> SET DATA METHOD IS ONLY AVAILABLE FOR SUCCESS RESPONSE
        'projectName' => 'my awesome project',
        .
        .
        .
    ])
    ->render();

$errorResponse = $this->errorResponse
    // ->setCode(xxxx)
    // ->setMessage("blah blah blah blah !")
    // ->setSuccessResponse(--boolean !!!--)
    // ->setResponseKey('error')
    // ->setResponseValue(--array-- => [ // --------------> SET ERROR METHOD IS ONLY AVAILABLE FOR ERROR RESPONSE
        'error text' => 'looks like something went wrong',
        .
        .
        .
    ])
    ->render();

$customResponse = $this->customResponse
    // ->setCode(XXXXX)
    // ->setMessage('BLAH BLAH BLAH !')
    // ->setSuccessStatus(BOOLEAN)
    // ->setResponseKey('additional')
    // ->setResponseValue([
    //    'custom text' => 'custom message here',
        .
        .
        .
    //])
    ->render();

```

Authors
-------

[](#authors)

- **Mojtaba Rakhisi** - *Initial work* - [github](https://github.com/mojtabarks)

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

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

Recently: every ~46 days

Total

7

Last Release

1770d ago

Major Versions

v1.1.0 → v2.0.02021-01-09

### Community

Maintainers

![](https://www.gravatar.com/avatar/46ad9194cdb329eedc055ac42bf3e62ae3012ff6b6bea75640ab3e385f934c26?d=identicon)[mojtabarks](/maintainers/mojtabarks)

---

Top Contributors

[![mojtabaRKS](https://avatars.githubusercontent.com/u/20111073?v=4)](https://github.com/mojtabaRKS "mojtabaRKS (47 commits)")

### Embed Badge

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

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

PHPackages © 2026

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