Download the PHP package ebsp/resting without Composer
On this page you can find all versions of the php package ebsp/resting. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package resting
Short Description Typed REST resources, validation, and OpenAPI generation for Laravel.
License MIT
Homepage https://github.com/ebsp/resting
Informations about the package 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.
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.
UnionResourcefor discriminator-tagged unions,DynamicResourcefor runtime field shapes. - OpenAPI 3 out of the box. Generate a spec from your route collection with no extra annotations.
Requirements
- PHP 8.2+
- Laravel 11 or 12
Installation
The service provider is auto-registered. Optionally publish the config:
Quickstart
Define a resource
Validate and parse a request
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
Or map a collection:
Field types
| Field | Description |
|---|---|
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 validation |
All fields support required(), nullable(), forbidden(), and omittedDefault().
Conditional validation
Predicate factories let you express rules like "shippingAddress is required when requiresShipping is true":
Polymorphic resources
UnionResource discriminates between resource shapes by a tag field:
DynamicResource lets you build resources at runtime:
OpenAPI generation
Resting can produce an OpenAPI 3 document from your registered routes:
Annotate routes with helper macros:
Resources, query parameters, and route metadata are turned into components.schemas, components.parameters, and paths automatically.
Documentation
Full documentation, including all field types, validation predicates, the marshaller, and OpenAPI generation, is available at ebsp.github.io/resting (coming soon).
Testing
Contributing
Issues and pull requests are welcome. Please run the test suite before submitting a PR.
License
Resting is open-sourced software licensed under the MIT license.