PHPackages                             021/restful-for-laravel - 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. 021/restful-for-laravel

ActiveLibrary[API Development](/categories/api)

021/restful-for-laravel
=======================

v1.0.1(6mo ago)220MITPHP

Since Oct 7Pushed 4mo agoCompare

[ Source](https://github.com/021-projects/restful-for-laravel)[ Packagist](https://packagist.org/packages/021/restful-for-laravel)[ RSS](/packages/021-restful-for-laravel/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

Restful for Laravel
===================

[](#restful-for-laravel)

What problem does this package solve?
-------------------------------------

[](#what-problem-does-this-package-solve)

This package provides a simple and elegant way to handle RESTful responses in Laravel applications. It allows you to define your data fetching logic and error handling in a clean and concise manner, reducing boilerplate code and improving readability. Restful for Laravel also supports exception handling: it consolidates errors into a single common form.

Requirements
------------

[](#requirements)

- PHP 8.1 or higher

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

[](#installation)

You can install the package via Composer:

```
composer require 021/restful-for-laravel
```

Response Structure
------------------

[](#response-structure)

### Success

[](#success)

You can pass to data any value that can be passed to `response()->json()`

### Error

[](#error)

```
{
  "errors": [
    {
      "code": "Error:Generic",
      "message": "Error message",
      /* optional */
      "meta": {
        /* any additional data here */
      }
    }
    /* more errors can be here */
  ]
}
```

Usage
-----

[](#usage)

```
use App\Http\Controllers\Controller;
use App\Repositories\FooRepository;
use App\Enums\Errors\BarError;
use O21\RestfulForLaravel\Contracts\EnumError;
use Illuminate\Http\JsonResponse;

enum BarError implements EnumError
{
    case FailedToFetchBars;

    public function message(): string
    {
        return match ($this) {
            self::FailedToFetchBars => 'Failed to fetch bars from external resource.',
        };
    }
}

class FooBarController extends Controller
{
    public function bar(): JsonResponse
    {
        return restful(
            data: fn (FooRepository $repo) => $repo->fetchBarsFromExternalResource(),
            fallback: fn (callable $toErrors) => $toErrors(
                errors: [
                    Bar::FailedToFetchBars,
                ],
                status: 503,
            ),
        );
    }
}
```

Just to compare, without this package, your `bar()` method would look like this:

```
public function bar(FooRepository $repo): JsonResponse
{
    try {
        return response()->json($repo->fetchBarsFromExternalResource());
    } catch (\Exception $e) {
        report($e);

        return response()->json([
            'errors' => [
                [
                    'code' => 'failed_to_fetch_bars',
                    'message' => 'Failed to fetch bars from external resource.',
                ],
            ],
        ], 503);
    }
}
```

More examples can be found in the [examples](examples) directory.

Need development services?
--------------------------

[](#need-development-services)

For expert assistance with developing or integrating any type of website or service, including financial applications, feel free to reach out to us at [studio.gnz.is](https://studio.gnz.is). We're here to help!

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance70

Regular maintenance activity

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

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

Total

2

Last Release

201d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/850e7a3d7b73d4aca00b33bfd13c33b97a8bec35d3b889d50cc0eec3b26eb337?d=identicon)[021-projects](/maintainers/021-projects)

---

Top Contributors

[![021-projects](https://avatars.githubusercontent.com/u/20326979?v=4)](https://github.com/021-projects "021-projects (3 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/021-restful-for-laravel/health.svg)

```
[![Health](https://phpackages.com/badges/021-restful-for-laravel/health.svg)](https://phpackages.com/packages/021-restful-for-laravel)
```

###  Alternatives

[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[essa/api-tool-kit

set of tools to build an api with laravel

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

A laravel wrapper package around the Facebook Conversions API

69145.4k](/packages/esign-laravel-conversions-api)[surface/laravel-webfinger

A Laravel package to create an ActivityPub webfinger.

113.8k](/packages/surface-laravel-webfinger)

PHPackages © 2026

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