PHPackages                             oktorino/midresapi - 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. oktorino/midresapi

ActiveLibrary

oktorino/midresapi
==================

Return consistency json structure, handling exception response, handling validation exception

v1.2.1(4y ago)136MITPHP

Since Feb 11Pushed 4y ago1 watchersCompare

[ Source](https://github.com/oktorino/midresapi)[ Packagist](https://packagist.org/packages/oktorino/midresapi)[ RSS](/packages/oktorino-midresapi/feed)WikiDiscussions main Synced 6d ago

READMEChangelog (3)DependenciesVersions (6)Used By (0)

 [![Quality Score](https://camo.githubusercontent.com/fd4157992fac7e4a45030a9cf8a4e1a68a1d158a3a55bdefda543ac1234dc569/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6f6b746f72696e6f2f6d69647265736170692e737667)](https://scrutinizer-ci.com/g/oktorino/midrespapi) [![Total Downloads](https://camo.githubusercontent.com/4c02f9add8875e21b63bf1849db7e7a6f35584b78aa63caf9be9b83f54db4f26/68747470733a2f2f706f7365722e707567782e6f72672f6f6b746f72696e6f2f6d69647265736170692f642f746f74616c2e737667)](https://packagist.org/packages/oktorino/midrespapi) [![Latest Stable Version](https://camo.githubusercontent.com/bfea8f18488d4ee416c23b4000e267e26f91f433cdc276275a5ae119257aeda6/68747470733a2f2f706f7365722e707567782e6f72672f6f6b746f72696e6f2f6d69647265736170692f762f737461626c652e737667)](https://packagist.org/packages/oktorino/midrespapi) [![License](https://camo.githubusercontent.com/10dca3c8bf64eebd9bd0bca5a0ff16d66ab1c99b2f2d7594f9e38984f5acee77/68747470733a2f2f706f7365722e707567782e6f72672f6f6b746f72696e6f2f6d69647265736170692f6c6963656e73652e737667)](https://packagist.org/packages/oktorino/midrespapi)

---

Midres api , return response with consistency structure in json,

- simple use.
- simple return models,collecton and also fractal transofrmer
- Handling exception.
- Handling validation exception.

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

[](#installation)

### Requires :

[](#requires-)

- PHP 7.2 \* or latest
- Laravel 7,8, or latest

Installation Midresapi in [Composer](https://getcomposer.org):

```
composer require oktorino/midresapi --dev
```

### Register to MiddlewareRoute

[](#register-to-middlewareroute)

Configure in kernel.php, and place at middllewareRoute :

```
'midresapi' => \Oktorino\Midresapi\ConsistencyStructure::class;
```

then call this "midresapi" on your api routes. example in api.php :

```
Route::get('/', function(){
    return response("response work !!!");
})->middleware("midresapi");
```

Usage &amp; Example
-------------------

[](#usage--example)

### return success message

[](#return-success-message)

```
 return "successs";
 #or
 return response("success");
```

response :

```
{
 "status_code": 200,
 "success": true,
 "message": "success",
 "data": null
}
```

### return with data

[](#return-with-data)

#### return model;

[](#return-model)

```
 $user=\App\User::first();
 return response($user);
```

response :

```
{
   "status_code": 200,
   "success": true,
   "message": "ok",
   "data": {
       "id": 1,
       "email": "admin@basahinajadeh.com",
       "username": "admin",
   }
}
```

#### return collection;

[](#return-collection)

```
 $users=\App\User::limit(2)->get();
 return response($users);
```

response :

```
{
   "status_code": 200,
   "success": true,
   "message": "ok",
   "data": [
       {
           "id": 5532,
           "email": "dancuk@dummy.com"
       },
       {
           "id": 5531,
           "email": "jancuk@dummy.com"
       }
   ]
}
```

that also support return fractal in tranformer

Failed Response
---------------

[](#failed-response)

- reponse mistakes

```
{
   "status_code": 500,
   "success": false,
   "message": "Something went wrong !!!",
   "data": null,
   "errors": [
       {
           "message": "Undefined variable: undefine_var",
           "file": "/home/tuah/apps/consistency_response/routes/api.php",
           "line": 24
       }
   ]
}
```

- Mistake on purpose ex :

```
  return response("can't be proccess");
```

```
{
   "status_code": 422,
   "success": false,
   "message": "can't proccess",
   "data": null
}
```

- Return failed validation

```
{
    "status_code": 422,
    "success": false,
    "message": "The given data was invalid.",
    "data": null,
    "errors": {
        "validation": [
            "The attendance no field is required."
        ]
    }
}
```

License
-------

[](#license)

midrespi createb by [Tuah Oktorino](https://www.linkedin.com/in/tuah-oktorino/).

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

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

Total

4

Last Release

1691d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5b30bf3f68f34effb1049274cd6e55d8b8282fc4cfc5eeeb0123056ae8a5226e?d=identicon)[oktorino](/maintainers/oktorino)

---

Top Contributors

[![oktorino](https://avatars.githubusercontent.com/u/64664340?v=4)](https://github.com/oktorino "oktorino (14 commits)")

---

Tags

composer-packagejsonphpresponse-experience

### Embed Badge

![Health badge](/badges/oktorino-midresapi/health.svg)

```
[![Health](https://phpackages.com/badges/oktorino-midresapi/health.svg)](https://phpackages.com/packages/oktorino-midresapi)
```

PHPackages © 2026

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