Download the PHP package maatify/api-response without Composer
On this page you can find all versions of the php package maatify/api-response. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package api-response
๐ฆ Maatify API Response
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. It is part of the modular Maatify.dev ecosystem.
๐ 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
- โ Environment toggles for logging
- โ
Optional
JsonResponseEmitter
for non-framework use
๐ Installation
Requires PHP 8.1+
Usesmaatify/slim-logger
under the hood for logging (installed automatically)
๐ฆ Usage in Slim
๐ก Usage in Pure PHP (no framework)
Use the built-in JsonResponseEmitter
class to send PSR-7 responses directly in native PHP.
๐ Output
โจ Example Slim Response
โ Supported Methods
Method | Description |
---|---|
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
Method | Status |
---|---|
missing() |
400 |
incorrect() |
400 |
invalid() |
400 |
notExist() |
400 |
success() |
200 |
dbError() |
500 |
tooManyAttempts() |
429 |
๐ Secure Logging
Enable structured logging in production via maatify/slim-logger
1. Enable in your .env
2. Sample Logged Output
Log file: logs/api/response.log
Log level: Info
๐ Directory Structure
๐งฉ Extend It
Want custom codes or more logic?
- Extend
BaseResponder
orCoreResponder
- Override any method (e.g. add audit log or rate limiter)
- Customize
logResponse()
for deeper monitoring
๐งช Testing
โ Run Tests
โ Run One Test
โ CI (GitHub Actions)
Tested on PHP 8.2, 8.3, and 8.4 using run-tests.yml
๐ Slim vs Pure PHP Comparison
Feature | Slim | Pure PHP |
---|---|---|
Routing | $app->post(... |
Native index.php or custom |
JSON Response | return Json::success(...) |
$response = Json::success(...) |
Headers/Status | Handled by Slim | You manually set headers + status |
Logging | Via maatify/slim-logger | โ Works the same |
๐ License
Maatify.dev
๐โโ๏ธ Questions or Feedback?
-
Open an issue on GitHub