jeevanjoshi/laravel-api-response

A simple and elegant API response formatter for Laravel

Maintainers

Package info

github.com/thecrazydiamond1/laravel-api-response

pkg:composer/jeevanjoshi/laravel-api-response

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-05-07 09:55 UTC

This package is auto-updated.

Last update: 2026-05-07 10:11:36 UTC


README

A simple and elegant API response formatter for Laravel.

Installation

composer require jeevanjoshi/laravel-api-response

The package will be auto-discovered by Laravel. No manual configuration needed.

Usage

use ApiResponse;

// Success response (200)
return ApiResponse::success($data, 'Users fetched');

// Created response (201)
return ApiResponse::created($data, 'User created');

// Paginated response (200)
return ApiResponse::paginated($users);

// Error response (500)
return ApiResponse::error('Something went wrong');

// Not found response (404)
return ApiResponse::notFound('User not found');

// Unauthorized response (401)
return ApiResponse::unauthorized();

// Forbidden response (403)
return ApiResponse::forbidden();

// Validation error response (422)
return ApiResponse::validation($errors);

// No content response (200)
return ApiResponse::noContent();

Response Structure

Success

{
    "success": true,
    "message": "Users fetched",
    "data": {}
}

Error

{
    "success": false,
    "message": "Something went wrong",
    "errors": null
}

Paginated

{
    "success": true,
    "message": "Success",
    "data": [],
    "meta": {
        "current_page": 1,
        "last_page": 5,
        "per_page": 15,
        "total": 75
    }
}

Validation

{
    "success": false,
    "message": "Validation failed",
    "errors": {
        "email": ["The email field is required"]
    }
}

License

MIT