uxmansarwar/response
is a powerful yet lightweight PHP package that makes it easy to manage structured API responses. Built with modern PHP practices, it follows a clean singleton pattern and supports result grouping, TTL, debug queries, and more. Ideal for Laravel, Symfony, WordPress, CodeIgniter, or raw PHP projects.
Developed and maintained by Uxman Sarwar, a senior PHP developer since 2013.
- Singleton-based fluent API
- Add results, errors, queries, TTL, and input metadata
- Auto-collects
$_GET
,$_POST
, and raw JSON input - Customizable result/error key groups with
key()
andindex()
- Get structured responses as JSON or array
- Great for APIs, microservices, and AJAX handlers
composer require uxmansarwar/response
use UxmanSarwar\Response;
Response::init();
Response::result(['id' => 1, 'name' => 'Alice']);
Response::error('Invalid request type');
Response::key('user')->index('info')->result(['email' => 'user@example.com']);
Response::ttl(60);
Response::query('SELECT * FROM users WHERE id = 1');
Response::input(true);
echo Response::json();
print_r(Response::array());
Response::init();
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
Response::error("Only POST requests are allowed");
} else {
$data = Response::$_INPUT;
if (empty($data['username'])) {
Response::error("Username is required");
} else {
Response::result("User registered successfully");
}
}
echo Response::json();
composer install
vendor/bin/phpstan analyse src --level=max
vendor/bin/pest
- Laravel: Replace default
response()->json()
with a fluent helper - WordPress: Handle AJAX with structured output
- Symfony: Wrap controller responses with grouped structure
- REST APIs: Make consistent error/result formatting
- Microservices: Inject debug info and TTL for downstream caching
This package is created by Uxman Sarwar, a full-stack PHP Laravel developer.
- GitHub: @uxmansarwar
- LinkedIn: Uxman Sarwar
- Email: uxmansrwr@gmail.com
If you found this package useful, consider β starring the repo and sharing it with other developers.
PHP API response library, structured API output PHP, response formatter, Laravel response helper, singleton response PHP, uxmansarwar response composer, REST API output PHP, error handler class PHP, api response json PHP, PHP response class Laravel
composer require uxmansarwar/response
Happy coding! π