PHPackages                             anhzf/laravel-rest-api - 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. [API Development](/categories/api)
4. /
5. anhzf/laravel-rest-api

ActiveLibrary[API Development](/categories/api)

anhzf/laravel-rest-api
======================

Laravel RestfulAPI management

v1.0.0(5y ago)07MITPHP

Since Sep 19Pushed 5y ago1 watchersCompare

[ Source](https://github.com/anhzf/Laravel-RestAPI)[ Packagist](https://packagist.org/packages/anhzf/laravel-rest-api)[ RSS](/packages/anhzf-laravel-rest-api/feed)WikiDiscussions 1.x Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Laravel-RestAPI
===============

[](#laravel-restapi)

Laravel Rest API management

Table of Content
----------------

[](#table-of-content)

- [Feature](#feature)
- [Installation](#installation)
- [JSON Data Schema](#api-response-json-data-structure)
- [Usage](#usage)
- [More Example](#example)

Feature
-------

[](#feature)

- Improve your API Response data structure

Installation
------------

[](#installation)

`composer require anhzf/laravel-rest-api`

API Response JSON data structure
--------------------------------

[](#api-response-json-data-structure)

```
{
  "success": true,
  "message": "your message here",
  "data": {
    "myData": "your data here..."
  },
  "errors": [
    "laravel", "automatically", "send", "exceptions", "here..."
  ]
}
```

Usage
-----

[](#usage)

### Methods

[](#methods)

- [APIResponse::message()](#add-message--apiresponsemessagestring-message)
- [APIResponse::data()](#add-data--apiresponsedataarray-data)
- [APIResponse::statusCode()](#set-http-status-code--apiresponsestatuscodeint-statuscode)
- [APIResponse::error()](#send-error-response--apiresponseerror)
- [Send Shortcut](#send-response-shortcut)
    - [APIResponse::sendMessage()](#send-response-shortcut)
    - [APIResponse::sendData()](#send-response-shortcut)
    - [APIResponse::sendStatusCode()](#send-response-shortcut)
    - [APIResponse::sendError()](#send-response-shortcut)

### Add Message | `APIResponse::message(string $message)`

[](#add-message--apiresponsemessagestring-message)

```
  use Anhzf\LaravelRestAPI\APIResponse;

  // end of some controller
  return APIResponse::message('[your message here]')->send();
```

### Add Data | `APIResponse::data(array $data)`

[](#add-data--apiresponsedataarray-data)

```
  use Anhzf\LaravelRestAPI\APIResponse;

  $myData = ['foo', 'bar', 'baz'];
  // end of some controller
  return APIResponse::data(compact('myData'))->send();
```

### Set HTTP Status Code | `APIResponse::statusCode(int $statusCode)`

[](#set-http-status-code--apiresponsestatuscodeint-statuscode)

```
  use Anhzf\LaravelRestAPI\APIResponse;

  // end of some controller
  return APIResponse::statusCode(404)
        ->message('Didn\'t find matched user!')
        ->send();
```

### Send Error Response | `APIResponse::error()`

[](#send-error-response--apiresponseerror)

It will send response without `success` key in your Json Response

```
  use Anhzf\LaravelRestAPI\APIResponse;

  // end of some controller
  return APIResponse::error()
      ->statusCode(422)
      ->message('email field is required!')
      ->send();
```

### Send Response Shortcut

[](#send-response-shortcut)

By adding `Send` verb in above listed method, it will be send response like using `send()`

```
  use Anhzf\LaravelRestAPI;

  class APIResponse {
    public static sendMessage(string $message);
    public static sendData(array $data);
    public static sendStatusCode(int $statusCode, bool $success = true);
    public static sendError(string $message = null, int $statusCode = JsonResponse::HTTP_BAD_REQUEST);
  }
```

### Example

[](#example)

```
  use Anhzf\LaravelRestAPI\APIResponse;

  return APIResponse::message('Fetched users data from database')
      ->sendData(compact('userData'));
```

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity55

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 ~0 days

Total

2

Last Release

2058d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/25a94cedcb2ac6eb093066d7f14c460f771302c626631a055ae7fca9c426684e?d=identicon)[anhzf](/maintainers/anhzf)

---

Top Contributors

[![anhzf](https://avatars.githubusercontent.com/u/36941633?v=4)](https://github.com/anhzf "anhzf (8 commits)")

### Embed Badge

![Health badge](/badges/anhzf-laravel-rest-api/health.svg)

```
[![Health](https://phpackages.com/badges/anhzf-laravel-rest-api/health.svg)](https://phpackages.com/packages/anhzf-laravel-rest-api)
```

###  Alternatives

[essa/api-tool-kit

set of tools to build an api with laravel

52680.5k](/packages/essa-api-tool-kit)[resend/resend-laravel

Resend for Laravel

1191.4M6](/packages/resend-resend-laravel)[flat3/lodata

OData v4.01 Producer for Laravel

96320.9k](/packages/flat3-lodata)[joggapp/laravel-aws-sns

Laravel package for the SNS events by AWS

3171.8k](/packages/joggapp-laravel-aws-sns)[simplestats-io/laravel-client

Client for SimpleStats!

4515.5k](/packages/simplestats-io-laravel-client)[spatie/spatie-price-api

The Price API used at promotional sites for our own products

1515.1k1](/packages/spatie-spatie-price-api)

PHPackages © 2026

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