Rest

phpnomad/rest is an MVC-driven methodology for defining REST APIs. It’s designed to let you describe controllers, routes, validations, and policies in a way that’s agnostic to the framework or runtime you plug into.

At its core:

By separating API definition (what the endpoint is, what it requires, what it returns) from integration (how it runs inside a host), you get REST endpoints that can move between stacks without rewrites.

Key ideas at a glance


The Request Lifecycle

When a request enters a system wired with phpnomad/rest, it moves through a consistent sequence of steps:

Route → Middleware → Controller → Response → Interceptors

Route

The RestStrategy matches an incoming request to a registered controller based on the HTTP method and path.

Middleware

Middleware runs before your controller logic.

Validations

Validation sets define input contracts for the request. These are set using a middleware, so you can control when they run.

Controller Handle Method

The controller is the core of the endpoint.

Interceptors

Interceptors run after the controller has produced a response and before the response leaves the pipeline.

They're usually used for two main purposes:

  1. Adapt the response — reshape or enrich the response object without touching controller code.
  2. Perform side effects — emit events, write audit logs, push metrics, etc.

Because interceptors sit at the boundary, they’re an ideal place to keep controllers lean while still achieving consistent output formats and cross-cutting behavior.