Nexus API Reference

RouteBuilder
in package

FinalYes

Fluent per-route configuration builder returned by HTTP verb methods.

RouteBuilder is the object you receive after calling $app->get(...), $app->post(...), etc. It lets you chain per-route settings — middleware and a named route identifier — before HttpApp::compile() freezes the builder into an immutable Route value object that drives the dispatcher.

The builder is intentionally mutable; the terminal compile() call on HttpApp converts all pending builders atomically and nothing else holds a reference to the builder after that point.

Example — adding per-route middleware and a name:

$app->post('/users', UserHandler::class)
    ->middleware(AuthenticationMiddleware::class)
    ->middleware(RateLimitMiddleware::class)
    ->name('user.create');
Tags
see
HttpApp::get()

Returns a RouteBuilder for GET routes

see
HttpApp::post()

Returns a RouteBuilder for POST routes

see
HttpApp::compile()

Freezes all pending builders into the compiled app

psalm-api

Table of Contents

Methods

__construct()  : mixed
build()  : Route
Freeze this builder into an immutable Route value object.
middleware()  : self
Append a PSR-15 middleware class name to this route's middleware chain.
name()  : self
Assign a human-readable name to this route for reverse routing and logging.

Methods

__construct()

public __construct(string $method, string $path, string|Closure $handler) : mixed
Parameters
$method : string
$path : string
$handler : string|Closure

build()

Freeze this builder into an immutable Route value object.

public build() : Route

Called internally by HttpApp::compile(); application code should not need to call this directly.

Return values
Route

middleware()

Append a PSR-15 middleware class name to this route's middleware chain.

public middleware(string $class) : self

Route middleware runs after global middleware and before the handler. Multiple calls append in order.

Parameters
$class : string

Fully-qualified class name of the PSR-15 middleware.

Return values
self

name()

Assign a human-readable name to this route for reverse routing and logging.

public name(string $name) : self
Parameters
$name : string

Unique route name within the application.

Return values
self

        
On this page

Search results