sharadkashyap/php-api-response-toolkit

A lightweight, framework-independent PHP toolkit for consistent JSON API responses and error handling.

Maintainers

Package info

github.com/sharadkashyapdev/php-api-response-toolkit

pkg:composer/sharadkashyap/php-api-response-toolkit

Transparency log

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v0.1.1 2026-07-15 05:56 UTC

This package is auto-updated.

Last update: 2026-07-15 06:32:14 UTC


README

PHP Version License

A lightweight, framework-independent PHP library for creating consistent and standardized JSON API responses.

Purpose

Provide a simple, reusable, and framework-independent way to generate consistent JSON API responses across PHP applications.

The goal of this library is to remove repetitive response formatting logic and provide a clean foundation for API development.

Features

  • Standard success responses
  • Standard error responses
  • Validation error responses
  • HTTP status helpers
  • Framework independent
  • PSR-4 autoloading
  • Lightweight and reusable
  • Consistent JSON output structure

Requirements

  • PHP 8.1+

Installation

Install using Composer:

composer require sharadkashyap/php-api-response-toolkit

Usage

Success Response

<?php

use SharadKashyap\ApiResponse\Response\SuccessResponse;

$response = new SuccessResponse(
    'User created successfully',
    [
        'id' => 1,
        'name' => 'John'
    ]
);

echo $response->toJson();

Example output:

{
    "success": true,
    "message": "User created successfully",
    "data": {
        "id": 1,
        "name": "John"
    }
}

Error Response

<?php

use SharadKashyap\ApiResponse\Response\ErrorResponse;

$response = new ErrorResponse(
    'User not found',
    404
);

echo $response->toJson();

Development

Clone the repository:

git clone https://github.com/sharadkashyap/php-api-response-toolkit.git

Install dependencies:

composer install

Quality Checks

Run unit tests:

vendor/bin/phpunit

Run static analysis:

vendor/bin/phpstan analyse

Check code formatting:

vendor/bin/php-cs-fixer fix --dry-run

Project Structure

src/
├── Contract/
├── Response/

tests/
└── Response/

Contributing

Contributions are welcome.

Please read:

before submitting a pull request.

Security

For security-related issues, please read:

Do not report security vulnerabilities through public issues.

Project Status

This project is currently under active development.

The initial public release focuses on providing a lightweight, framework-independent API response toolkit for PHP.

License

MIT License