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 3w ago

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 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

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

Total

2

Last Release

2112d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/36941633?v=4)[Alwan Nuha](/maintainers/anhzf)[@anhzf](https://github.com/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

[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.3k3](/packages/defstudio-telegraph)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[resend/resend-laravel

Resend for Laravel

1222.7M9](/packages/resend-resend-laravel)[flat3/lodata

OData v4.01 Producer for Laravel

99351.7k](/packages/flat3-lodata)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[api-platform/laravel

API Platform support for Laravel

58171.4k14](/packages/api-platform-laravel)

PHPackages © 2026

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