PHPackages                             ebsp/resting - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. ebsp/resting

ActiveLibrary[HTTP &amp; Networking](/categories/http)

ebsp/resting
============

Typed REST resources, validation, and OpenAPI generation for Laravel.

v7.3.0(4w ago)38.9k↓62.3%2[4 issues](https://github.com/ebsp/resting/issues)MITPHPPHP ^8.2CI failing

Since Mar 11Pushed 4w ago2 watchersCompare

[ Source](https://github.com/ebsp/resting)[ Packagist](https://packagist.org/packages/ebsp/resting)[ Docs](https://github.com/ebsp/resting)[ RSS](/packages/ebsp-resting/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (14)Versions (87)Used By (0)

Resting
=======

[](#resting)

**Typed REST resources, validation, and OpenAPI generation for Laravel.**

Resting is an alternative to Laravel's built-in API Resources, built around typed field objects. Each resource property is a strongly-typed `Field` that knows how to parse, validate, and format itself — so request payloads, validation rules, response shapes, and OpenAPI schemas all derive from a single source of truth.

```
class UserResource extends \Seier\Resting\Resource
{
    public StringField $name;
    public IntField $age;

    public function __construct()
    {
        $this->name = new StringField();
        $this->age = new IntField();
    }
}
```

Why Resting?
------------

[](#why-resting)

- **One definition, many uses.** A resource serves as the request schema, the validator, the response shape, and the OpenAPI component. No duplicated `FormRequest` + `Resource` + Swagger annotations.
- **Strongly typed fields.** Every field knows its own type, parser, and validators — no string-keyed validation rules to keep in sync with response transformers.
- **Composable validation.** Per-field validators, predicate-based conditional validation (`whenProvided`, `whenEquals`, …), and resource-level cross-field comparisons (`lessThan`, `equal`, …).
- **Polymorphic resources.** `UnionResource` for discriminator-tagged unions, `DynamicResource` for runtime field shapes.
- **OpenAPI 3 out of the box.** Generate a spec from your route collection with no extra annotations.

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

[](#requirements)

- PHP **8.2+**
- Laravel **11** or **12**

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

[](#installation)

```
composer require ebsp/resting
```

The service provider is auto-registered. Optionally publish the config:

```
php artisan vendor:publish --tag=config --provider="Seier\Resting\Support\Laravel\RestingServiceProvider"
```

Quickstart
----------

[](#quickstart)

### Define a resource

[](#define-a-resource)

```
use Seier\Resting\Resource;
use Seier\Resting\Fields\IntField;
use Seier\Resting\Fields\StringField;

class UserResource extends Resource
{
    public StringField $name;
    public IntField $age;

    public function __construct()
    {
        $this->name = (new StringField())->trim();
        $this->age = (new IntField())->required();
    }
}
```

### Validate and parse a request

[](#validate-and-parse-a-request)

```
Route::post('/users', function (Request $request) {
    $user = (new UserResource())->set($request->all());

    // Persist…
    return $user;
});
```

`Resource` implements Laravel's `Jsonable`, so returning the resource is enough — Laravel encodes it as JSON automatically. Invalid input throws `Illuminate\Validation\ValidationException` with nested error paths.

### Build a response

[](#build-a-response)

```
return (new UserResource())->set($model->toArray());
```

Or map a collection:

```
return (new UserResource())->mapMany(
    $users,
    fn (UserResource $r, User $u) => $r->set($u->toArray()),
);
```

Field types
-----------

[](#field-types)

FieldDescription`StringField`Strings, with `trim()`, `upper()`, `lower()`, `stripWhitespace()`, `transform()` transformers`IntField`Integers, with numeric validators (`min`, `max`, `between`, …)`NumberField`Floats / decimals`BoolField`Booleans (parses `true/false`, `1/0`, `yes/no`)`EnumField`PHP backed enums (string or int)`CarbonField`Date-times (returns `CarbonImmutable`)`CarbonPeriodField`Date ranges as `CarbonPeriod``TimeField`Time-of-day without date`ArrayField`Homogeneous arrays with element-type validation`ResourceField`Single nested resource`ResourceArrayField`Array of nested resources`RawField`Pass-through, no parsing or validationAll fields support `required()`, `nullable()`, `forbidden()`, and `omittedDefault()`.

Conditional validation
----------------------

[](#conditional-validation)

Predicate factories let you express rules like *"`shippingAddress` is required when `requiresShipping` is true"*:

```
use function Seier\Resting\Validation\Predicates\whenEquals;

public function __construct()
{
    $this->requiresShipping = new BoolField();
    $this->shippingAddress = (new StringField())
        ->required(whenEquals($this->requiresShipping, true));
}
```

Polymorphic resources
---------------------

[](#polymorphic-resources)

`UnionResource` discriminates between resource shapes by a tag field:

```
class AnimalResource extends UnionResource
{
    public function __construct()
    {
        parent::__construct('type', fn () => [
            'cat' => new CatResource(),
            'dog' => new DogResource(),
        ]);
    }
}
```

`DynamicResource` lets you build resources at runtime:

```
$resource = (new DynamicResource())
    ->withField('name', new StringField())
    ->withField('count', new IntField());
```

OpenAPI generation
------------------

[](#openapi-generation)

Resting can produce an OpenAPI 3 document from your registered routes:

```
use Seier\Resting\Support\OpenAPI;

$spec = (new OpenAPI(Route::getRoutes()))->toArray();
```

Annotate routes with helper macros:

```
Route::post('/users', UserController::class)
    ->docs('Create a new user.')
    ->lists(UserResource::class);
```

Resources, query parameters, and route metadata are turned into `components.schemas`, `components.parameters`, and `paths` automatically.

Documentation
-------------

[](#documentation)

Full documentation, including all field types, validation predicates, the marshaller, and OpenAPI generation, is available at **[ebsp.github.io/resting](https://ebsp.github.io/resting)** *(coming soon)*.

Testing
-------

[](#testing)

```
composer install
vendor/bin/phpunit
```

Contributing
------------

[](#contributing)

Issues and pull requests are welcome. Please run the test suite before submitting a PR.

License
-------

[](#license)

Resting is open-sourced software licensed under the [MIT license](LICENSE).

###  Health Score

55

—

FairBetter than 97% of packages

Maintenance74

Regular maintenance activity

Popularity28

Limited adoption so far

Community15

Small or concentrated contributor base

Maturity85

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 81.8% 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 ~34 days

Recently: every ~17 days

Total

67

Last Release

28d ago

Major Versions

v2.6.0 → v3.0.02020-12-18

v3.0.0 → v4.0.02021-02-01

v4.9.0 → v5.0.02021-12-29

v5.20.0 → v6.0.02026-03-11

v6.2.0 → v7.0.02026-03-25

PHP version history (4 changes)v4.0.0PHP ^7.0 || ^8.0

v5.2.0PHP ^8.0

v5.4.0PHP ^8.2

v6.0.0PHP ^8.2|^8.3|^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/94b0a2b01d629673d5ecb75671a3097d225b695c58a17ac11954aff49ebc6fa1?d=identicon)[ebsp](/maintainers/ebsp)

---

Top Contributors

[![ebsp](https://avatars.githubusercontent.com/u/1406975?v=4)](https://github.com/ebsp "ebsp (63 commits)")[![Thomas-Rosenkrans-Vestergaard](https://avatars.githubusercontent.com/u/15520300?v=4)](https://github.com/Thomas-Rosenkrans-Vestergaard "Thomas-Rosenkrans-Vestergaard (11 commits)")[![aawnu](https://avatars.githubusercontent.com/u/2266126?v=4)](https://github.com/aawnu "aawnu (1 commits)")[![KLIM8D](https://avatars.githubusercontent.com/u/786271?v=4)](https://github.com/KLIM8D "KLIM8D (1 commits)")[![zethzeth](https://avatars.githubusercontent.com/u/5783787?v=4)](https://github.com/zethzeth "zethzeth (1 commits)")

---

Tags

apilaravelvalidationrestswaggeropenapitransformerresources

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ebsp-resting/health.svg)

```
[![Health](https://phpackages.com/badges/ebsp-resting/health.svg)](https://phpackages.com/packages/ebsp-resting)
```

###  Alternatives

[api-platform/core

Build a fully-featured hypermedia or GraphQL API in minutes!

2.6k50.1M314](/packages/api-platform-core)[vyuldashev/laravel-openapi

Generate OpenAPI Specification for Laravel Applications

4621.2M](/packages/vyuldashev-laravel-openapi)[api-platform/laravel

API Platform support for Laravel

59156.3k11](/packages/api-platform-laravel)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59659.4k](/packages/lomkit-laravel-rest-api)[tartanlegrand/laravel-openapi

Generate OpenAPI Specification for Laravel Applications

38201.0k2](/packages/tartanlegrand-laravel-openapi)[noitran/opendox

OpenApi(Swagger) 3.0 package for Lumen 5.5+ and Laravel 5.5+ with REDOC UI and SwaggerUI 3

2214.2k](/packages/noitran-opendox)

PHPackages © 2026

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