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

ActiveLibrary[API Development](/categories/api)

maatify/api-response
====================

Slim-compatible JSON API response handler for validation, errors, and success messages.

1.0.2(1y ago)01MITPHPPHP &gt;=8.2.0CI passing

Since Apr 18Pushed 1y ago1 watchersCompare

[ Source](https://github.com/Maatify/api-response)[ Packagist](https://packagist.org/packages/maatify/api-response)[ Docs](https://github.com/Maatify/)[ RSS](/packages/maatify-api-response/feed)WikiDiscussions main Synced today

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

📦 Maatify API Response
======================

[](#-maatify-api-response)

[![Maatify.dev](https://camo.githubusercontent.com/bb8bf9ee079d7f823c9d5e94061d1d4c11dc0898e2b1b5cc9a8a7b04d8bfdd7d/68747470733a2f2f7777772e6d6161746966792e6465762f6173736574732f696d672f696d672f6d6161746966795f6c6f676f5f77686974652e737667)](https://camo.githubusercontent.com/bb8bf9ee079d7f823c9d5e94061d1d4c11dc0898e2b1b5cc9a8a7b04d8bfdd7d/68747470733a2f2f7777772e6d6161746966792e6465762f6173736574732f696d672f696d672f6d6161746966795f6c6f676f5f77686974652e737667)

[![Current version](https://camo.githubusercontent.com/54ea31472069f0f48112f1329dc9e40527fa387fa5981e744c4b60ae931372a0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6161746966792f6170692d726573706f6e7365)](https://packagist.org/packages/maatify/api-response)[![PHP Version Support](https://camo.githubusercontent.com/e8c936d48dd9b4d843a52afa60b2d207669bd1860af6d9e46b0bdb322d39cda8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6d6161746966792f6170692d726573706f6e7365)](https://packagist.org/packages/maatify/api-response)[![Monthly Downloads](https://camo.githubusercontent.com/04aa7775d6f8bc71e51d793cb3d33d95e3c88241c080ee831ea1e9ff4400975d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f646d2f6d6161746966792f6170692d726573706f6e7365)](https://packagist.org/packages/maatify/api-response/stats)[![Total Downloads](https://camo.githubusercontent.com/65f8f1b0363b975e98441ecbeb1be9aa3e0d3cf87cd6772b923ded3debb47087/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6161746966792f6170692d726573706f6e7365)](https://packagist.org/packages/maatify/api-response/stats)[![Stars](https://camo.githubusercontent.com/11aebf44d9d7e294f4c8c778767015ad561ca1eed518ae6712a4421f028ed2c2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f73746172732f6d6161746966792f6170692d726573706f6e7365)](https://github.com/maatify/api-response/stargazers)[![Tests](https://github.com/maatify/api-response/actions/workflows/run-tests.yml/badge.svg)](https://github.com/maatify/api-response/actions)

---

**Maatify API Response** is a lightweight, PSR-7 compatible, Slim-friendly structured JSON response library for clean and consistent API responses. Built with production logging in mind via [maatify/slim-logger](https://github.com/maatify/slim-logger). It is part of the modular [Maatify.dev](https://www.maatify.dev) ecosystem.

---

🚀 Features
----------

[](#-features)

- ✅ PSR-7 compatible (`ResponseInterface`)
- ✅ Slim-ready (`return Json::...`)
- ✅ Structured error responses (missing, invalid, etc.)
- ✅ Success responses with metadata
- ✅ Automatic route+line trace: `user:login::55`
- ✅ Production-safe JSON POST logging via [maatify/slim-logger](https://github.com/maatify/slim-logger)
- ✅ Environment toggles for logging
- ✅ Optional `JsonResponseEmitter` for non-framework use

---

🛠 Installation
--------------

[](#-installation)

```
composer require maatify/api-response
```

> Requires PHP 8.1+
> Uses `maatify/slim-logger` under the hood for logging (installed automatically)

---

📦 Usage in Slim
---------------

[](#-usage-in-slim)

```
use Maatify\ApiResponse\Json;

$app->post('/register', function ($request, $response) {
    return Json::missing($response, 'email');
});
```

---

💡 Usage in Pure PHP (no framework)
----------------------------------

[](#-usage-in-pure-php-no-framework)

Use the built-in `JsonResponseEmitter` class to send PSR-7 responses directly in native PHP.

```
require 'vendor/autoload.php';

use Maatify\ApiResponse\Json;
use Maatify\ApiResponse\JsonResponseEmitter;
use Nyholm\Psr7\Response;

$response = new Response();

if (empty($_POST['email'])) {
    $response = Json::missing($response, 'email', 'Email is required', __LINE__);
}

JsonResponseEmitter::emit($response);
```

---

### 🔁 Output

[](#-output)

```
HTTP/1.1 400 Bad Request
Content-Type: application/json
```

```
{
  "success": false,
  "response": 1000,
  "var": "email",
  "description": "MISSING Email",
  "more_info": "Email is required",
  "error_details": "index::15"
}
```

---

✨ Example Slim Response
-----------------------

[](#-example-slim-response)

```
{
  "success": false,
  "response": 1000,
  "var": "email",
  "description": "MISSING Email",
  "more_info": "",
  "error_details": "register::34"
}
```

---

✅ Supported Methods
-------------------

[](#-supported-methods)

MethodDescription`missing()`Field missing from input`incorrect()`Incorrect format or value`invalid()`Invalid input`notExist()`Value doesn't exist (e.g. user ID)`success()`Standard success output`dbError()`Internal DB/system error`tooManyAttempts()`Rate limit exceeded---

📊 HTTP Status Code Reference
----------------------------

[](#-http-status-code-reference)

MethodStatus`missing()``400``incorrect()``400``invalid()``400``notExist()``400``success()``200``dbError()``500``tooManyAttempts()``429`---

🔐 Secure Logging
----------------

[](#-secure-logging)

Enable structured logging in production via [maatify/slim-logger](https://github.com/maatify/slim-logger)

### 1. Enable in your `.env`

[](#1-enable-in-your-env)

```
JSON_POST_LOG=1
```

### 2. Sample Logged Output

[](#2-sample-logged-output)

```
{
  "response": {
    "success": false,
    "response": 1000
  },
  "posted_data": {
    "email": "user@test.com",
    "password": "******"
  }
}
```

**Log file:** `logs/api/response.log`
**Log level:** `Info`

---

📂 Directory Structure
---------------------

[](#-directory-structure)

```
src/
├── CoreResponder.php        # Base logic + logger
├── BaseResponder.php        # Validation & error helpers
└── Json.php                 # Final static entrypoint class
└── JsonResponseEmitter.php  # Sends PSR-7 responses in native PHP

```

---

🧩 Extend It
-----------

[](#-extend-it)

Want custom codes or more logic?

- Extend `BaseResponder` or `CoreResponder`
- Override any method (e.g. add audit log or rate limiter)
- Customize `logResponse()` for deeper monitoring

---

🧪 Testing
---------

[](#-testing)

### ✅ Run Tests

[](#-run-tests)

```
composer test
```

### ✅ Run One Test

[](#-run-one-test)

```
composer test -- --filter testSuccessResponse
```

### ✅ CI (GitHub Actions)

[](#-ci-github-actions)

Tested on PHP 8.2, 8.3, and 8.4 using [run-tests.yml](.github/workflows/run-tests.yml)

---

🆚 Slim vs Pure PHP Comparison
-----------------------------

[](#-slim-vs-pure-php-comparison)

FeatureSlimPure PHPRouting`$app->post(...`Native `index.php` or customJSON Response`return Json::success(...)``$response = Json::success(...)`Headers/StatusHandled by SlimYou manually set headers + statusLoggingVia maatify/slim-logger✅ Works the same---

📄 License
---------

[](#-license)

[MIT License](./LICENSE) © 2025 [Maatify.dev](https://maatify.dev)

---

🙋‍♂️ Questions or Feedback?
---------------------------

[](#‍️-questions-or-feedback)

- Open an issue on [GitHub](https://github.com/maatify/slim-logger)

---

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance44

Moderate activity, may be stable

Popularity1

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 80% 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 ~0 days

Total

2

Last Release

441d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a885a0810f2762586520ab284c9019aaf0b650b53cdf2a6c13ea10931bb7795?d=identicon)[Maatify](/maintainers/Maatify)

---

Top Contributors

[![megyptm](https://avatars.githubusercontent.com/u/33574895?v=4)](https://github.com/megyptm "megyptm (4 commits)")[![Maatify](https://avatars.githubusercontent.com/u/130119162?v=4)](https://github.com/Maatify "Maatify (1 commits)")

---

Tags

responsejsonapimaatify

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[algolia/algoliasearch-client-php

API powering the features of Algolia.

69735.1M159](/packages/algolia-algoliasearch-client-php)[telnyx/telnyx-php

Official Telnyx PHP SDK — APIs for Voice, SMS, MMS, WhatsApp, Fax, SIP Trunking, Wireless IoT, Call Control, and more. Build global communications on Telnyx's private carrier-grade network.

35789.4k2](/packages/telnyx-telnyx-php)[mollie/mollie-api-php

Mollie API client library for PHP. Mollie is a European Payment Service provider and offers international payment methods such as Mastercard, VISA, American Express and PayPal, and local payment methods such as iDEAL, Bancontact, SOFORT Banking, SEPA direct debit, Belfius Direct Net, KBC Payment Button and various gift cards such as Podiumcadeaukaart and fashioncheque.

60216.0M83](/packages/mollie-mollie-api-php)[obiefy/api-response

Simple Laravel package to return Json responses.

17325.0k](/packages/obiefy-api-response)[nilportugues/jsonapi-bundle

Symfony 2 &amp; 3 JSON API Transformer Package

11446.7k](/packages/nilportugues-jsonapi-bundle)[nilportugues/api-problems

PSR7 Response implementation for the Problem Details for HTTP APIs

1749.6k2](/packages/nilportugues-api-problems)

PHPackages © 2026

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