Technology1 min read

Laravel Rest Api 3.0: Typed Fields, Metrics, and OpenAPI Docs

By · Published by Everything Blog

In short

The redesigned resource architecture relies on typed fields like Text, Integer, and Enum to simultaneously govern validation, filtering, formatting, and documentation. Built-in metric endpoints allow developers to calculate averages, trends, and counts without writing custom controller code, all while honoring existing authorization rules. To prevent accidental data loss, the package incorporates an action confirmation workflow alongside concurrency checks that return a 409 status code for stale data. Client responses also include localized messaging in English and French.

Key points

  • Laravel Rest Api 3.0 replaces most of its underlying code while preserving the core singl…: Laravel Rest Api 3.0 replaces most of its underlying code while preserving the core single resource class model.
  • Dedicated metric endpoints generate analytical calculations without requiring dedicated c…: Dedicated metric endpoints generate analytical calculations without requiring dedicated controller code.
  • Search features continue to accommodate basic database indexes alongside Laravel Scout dr…: Search features continue to accommodate basic database indexes alongside Laravel Scout drivers like Meilisearch, Algolia, and Typesense.

Sources checked by our analysis pipeline: 1

Gautier Deleglise just released Laravel Rest Api 3.0, a rebuild of the package that turns your Eloquent models into a REST API from a single resource class. We first covered it when it launched in 2023 and again when it added Laravel Scout support. Version 3.0 keeps the same idea and replaces most of what sits underneath it.

Some of the highlights include:

- Typed fields that drive filters, validation, response values, and the API docs

- OpenAPI documentation through Scramble

- Metric endpoints for counts, trends, partitions, progress, and tables

- Confirmations for actions and bulk writes, using a

428

response and a signed token

Typed Fields

In 2.x, a resource listed column names. In 3.0, a resource declares typed fields with Text

, Integer

, Number

, Date

, Enum

, Json

, and more:

public function fields(): array { return [ ID::make('id'), Text::make('title')->rules('max:80')->creationRules('required'), Integer::make('seats')->rules('min:0'), Enum::make('status', ShowStatus::class)->offered([ShowStatus::Planned, ShowStatus::OnSale]), Date::make('starts_on')->creationRules('required'), ]; }

The package uses that one declaration for the rest of the API:

- Filters only accept operators that fit the field's type. Anything else returns a

422

Technology