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

ActiveLibrary[API Development](/categories/api)

swapnil/api-response-creator
============================

Package to give common exit point to handle api responses with multiple error codes.

v1.00.04(10y ago)0211MITPHPPHP &gt;=5.4.0

Since Apr 19Pushed 9y ago1 watchersCompare

[ Source](https://github.com/Anshdesire/ApiResponse)[ Packagist](https://packagist.org/packages/swapnil/api-response-creator)[ RSS](/packages/swapnil-api-response-creator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (1)Versions (6)Used By (0)

ApiResponse
===========

[](#apiresponse)

Maintained by @anshdesire, Laravel api reponse generatorin the laravel 5 application. and published to packagist() .

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

[](#installation)

You can install the package through Composer.

composer require swapnil/api-response-creator

```
You must install this service provider. Make this the very first provider in list.

```php

'providers' => [
    'Swapnil\ApiResponse\ServiceProvider',
    //...
];

```

Publish
-------

[](#publish)

php artisan vendor:publish

Use
---

[](#use)

```
return \ApiResponse::respond($data, $status = true,$headers = []);

return \ApiResponse::setStatusCode(200);

return  \ApiResponse::setErrorCode(200); //with error code given in cofig.

return \ApiResponse::getStatusCode();

return \ApiResponse::getStatusCodeList()[404];

return \ApiResponse::respondWithPagination(Paginator $items, $data, $status= true); // if pagination data needs to be send then

Method chaining can also be used here.

 return \ApiResponse::setStatusCode(200)->ApiResponse::respondWithPagination(Paginator $items, $data, $status= true);

 Standard json response structure

 {
  "status_code": 422,
  "errors": [
    {
      "error_message": "Validation error.",
      "error_code": 2004,
      "error_data": {
        "user_name": [
          "The user name has already been taken."
        ],
        "mobile": [
          "The mobile has already been taken."
        ]
      }
    }
  ],
  "data": [],
  "paginator": [],
  "success": false,
  "success_message": "Unprocessed entity"
}

All kind of error codes and error messages can be configured in swapnil.api-response.php config file.

    'status_code' => 200,
    'status_code_list' => [
      200 => 200,
      422 => 422,
      201 => 201,
      404 => 404,
      500 => 500,
    ],
    'status_code_messages' => [
          200 => 'Request successfully processed.',
          422 => 'Unprocessed entity',
          201 => 'Created.',
          404 => '',
          500 => 'Internal Server Error.',
    ],
    'errors_list' => [ // configurable
    '2001' => [
      'error_message' => 'User not found or wrong credentials.',
      'error_code' => 2001,
          'error_data' => '',
        ],

    '2002' => [
      'error_message' => '2002',
      'error_code' => 2002,
          'error_data' => '',
        ],

    '2003' => [
          'error_message' => 'Unable to create.',
          'error_code' => 2003,
          'error_data' => '',
        ],

    '2004' => [
          'error_message' => 'Validation error.',
          'error_code' => 2004,
          'error_data' => '',
      ]
     ],

```

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](https://github.com/Anshdesire/ApiResponse/blob/master/LICENSE.txt) for more information.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

5

Last Release

3666d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9501c69740d2b4bd7bc5d7ef3007a29e0744b3ba2fa6e751eb6ac130e9364c0e?d=identicon)[swapnilgeek](/maintainers/swapnilgeek)

---

Top Contributors

[![tripathi-swapnil](https://avatars.githubusercontent.com/u/2109474?v=4)](https://github.com/tripathi-swapnil "tripathi-swapnil (23 commits)")

---

Tags

apiresponses

### Embed Badge

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

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

###  Alternatives

[andreaselia/laravel-api-to-postman

Generate a Postman collection automatically from your Laravel API

1.0k586.2k3](/packages/andreaselia-laravel-api-to-postman)[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[specialtactics/l5-api

Dependencies for the Laravel API Boilerplate package

3672.8k2](/packages/specialtactics-l5-api)

PHPackages © 2026

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