PHPackages                             hyder/json-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. hyder/json-response

ActiveLibrary

hyder/json-response
===================

Json response handling for HTTP request.

3.0.3(4mo ago)2374MITPHPPHP ^7.3|^8.0

Since Mar 31Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/abhihyder/json-response)[ Packagist](https://packagist.org/packages/hyder/json-response)[ RSS](/packages/hyder-json-response/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (11)Used By (0)

JSON-Response Laravel Package
=============================

[](#json-response-laravel-package)

Overview
--------

[](#overview)

The JSON-Response package provides a simple and minimalistic interface for handling JSON responses in your Laravel applications. It offers convenient methods for returning success responses and error responses with standardized formats.

Installing
----------

[](#installing)

You can install the JSON-Response package via Composer. Run the following command in your terminal:

```
composer require hyder/json-response
```

Optional
--------

[](#optional)

The service provider will automatically get registered. Or you may manually add the service provider in your `config/app.php` file:

```
'providers' => [
    // ...
    Hyder\JsonResponse\JsonResponseServiceProvider::class,
];
```

Uses
----

[](#uses)

### Basic Usage

[](#basic-usage)

To use the JSON-Response package, you need to import the JsonResponse facade and make use of its methods in your controllers or routes.

```
use Hyder\JsonResponse\Facades\JsonResponse;

// ...

public function store(Request $request)
{
    try {

        // Validate the incoming request
        $validator = Validator::make($request->all(), [
            // Validation rules
        ]);

        // Check if validation fails
        if ($validator->fails()) {
            // Return a validation error response
            return JsonResponse::validationError($validator->errors());
        }

        // Process the request and create a new resource

        // Return a success response
        return JsonResponse::created($message);
    } catch(\Exception $ex){
        return JsonResponse::internalError($ex->getMessage());
    }

}

public function update(Request $request, $id)
{
    // Process the request and update the specified resource

    // Return a success response
    return JsonResponse::updated($message);
}
```

### Available Success Methods

[](#available-success-methods)

The following methods are available for returning success responses:

1. `created($message = "Data created successfully!", $data = null)`
    Returns a response with a 201 Created status code, a success message, and optional data.
2. `updated($message = "Data updated successfully!", $data = null)`
    Returns a response with a 200 OK status code, a success message, and optional data.
3. `success($message = "Request completed successfully!")`
    Returns a response with a 200 OK status code and a success message.
4. `data($data, $message = "Data fetched successfully!")`
    Returns a response with a 200 OK status code, a success message, and the provided data.

### Method Chaining

[](#method-chaining)

You can chain methods together for more flexibility:

```
// Return a success response with a custom status code and message
return JsonResponse::statusCode($statusCode)->success('Your message');

// Return a success response with a custom status code, header, and message
return JsonResponse::statusCode($statusCode)->withHeader($header)->success('Your message');
```

Please note that the `statusCode()` method will not affect the chaining when using the `created()` method.

### Success Response

[](#success-response)

```
{
  "success": true,
  "message": "Your message",
  "data": {
    // ...
  }
}
```

### Available Error Methods

[](#available-error-methods)

The following methods are available for returning error responses:

1. `badRequest($message = "Bad request!")`
    Returns a response with a 400 Bad Request status code and an optional error message. This method is used to indicate a general "bad request" error.
2. `unauthenticated($message = 'Unauthenticated!')`
    Returns a response with a 401 Unauthorized status code and an optional error message. It is used to indicate that the user making the request is not authenticated.
3. `invalidRequest($message = 'Invalid request!')`
    Returns a response with a 403 Forbidden status code and an optional error message. It is used to indicate that the request is invalid or does not meet the server's expectations.
4. `validationError($message = 'Required field is missing!')`
    Returns a response with a 422 Unprocessable Entity status code and an optional error message. It is used to indicate that the request data failed validation checks.
5. `notFound($message = 'Not found!')`
    Returns a response with a 404 Not Found status code and an optional error message. It is used to indicate that the requested resource was not found.
6. `internalError($message = 'Internal server error!')`
    Returns a response with a 500 Internal Server Error status code and an optional error message. It is used to indicate that an unexpected internal server error occurred.
7. `error($message = 'Something went wrong!', int $statusCode = 500)`
    Returns a response with the specified status code and error message.

Please note that you can provide a custom error message for each error response if needed.

Feel free to adjust the method names and default error messages to better suit your application's needs.

### Chaining with error method

[](#chaining-with-error-method)

You can chain methods together for more flexibility:

```
// Return a error response with a custom status code and message
return JsonResponse::statusCode($statusCode)->error($message);

// Return a error response with a custom status code, header, and message
return JsonResponse::withHeader($header)->error($message, 400);
```

Please note that the `statusCode()` method will affect only when chaining with `error()` method.

### Response

[](#response)

```
{
  "success": false,
  "message": "Your message" // Message can contain any data type
}
```

### Customized Response

[](#customized-response)

In addition to the provided methods, you can also return a customized JSON response using the `response()` method. This method allows you to specify the data, status code, and headers for the response.

```
// Return a custom response with a custom status code and data
return JsonResponse::statusCode($statusCode)->response($array);

// Return a custom response with a custom status code, header, and data
return JsonResponse::statusCode($statusCode)->withHeader($header)->response($array);
```

### License

[](#license)

This package is open-source software licensed under the MIT license.

### Credits

[](#credits)

This package is developed and maintained by Tofayel Hyder Abhi.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance75

Regular maintenance activity

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~112 days

Recently: every ~90 days

Total

10

Last Release

138d ago

Major Versions

1.0.2 → 2.0.02023-05-11

2.0.2 → 3.0.02025-05-18

### Community

Maintainers

![](https://www.gravatar.com/avatar/7fb98d8b7606987af9dc221ddb38c6031b28c6d60257d028f2117072e298b103?d=identicon)[abhihyder](/maintainers/abhihyder)

---

Top Contributors

[![abhihyder](https://avatars.githubusercontent.com/u/55033824?v=4)](https://github.com/abhihyder "abhihyder (16 commits)")

---

Tags

responselaraveljson-responsehyder

### Embed Badge

![Health badge](/badges/hyder-json-response/health.svg)

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

###  Alternatives

[dugajean/laravel-yaml

YAML parser for Laravel.

144.8k](/packages/dugajean-laravel-yaml)

PHPackages © 2026

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