← Routing & Handlers

ROUTING & HANDLERS FEATURE

Basic Route

One small payload class defines the endpoint. One small handler fills the response resource.

Feature Guide

A quick orientation block that answers the essential questions: what this feature does, how it works, why it matters, and the key concepts behind it.

What this does

A single #[AsPayload] attribute on a PHP class creates a fully routed HTTP endpoint — no XML, no YAML, no config files.

How it works

The framework scans the Composer classmap for classes with #[AsPayload], extracts path and method metadata, resolves env:: placeholders if present, and registers routes at boot. The route compiler then turns path patterns into optimized regex matchers cached in memory.

Why it matters

Keeping route definitions co-located with their request DTOs means a reader can understand what an endpoint accepts and where it lives by reading a single file. At the same time, env:: syntax lets operations move a route without reopening PHP code when deployment topology demands it.

Key concepts

#[AsPayload]
Attribute that marks a class as a request DTO and declares its HTTP route.
env::VAR_NAME::/default/path
Special attribute syntax that lets a payload read its route path, name, or other metadata from .env with a safe default fallback.
responseWith
Links the payload to the Resource DTO that shapes the response.
ClassDiscovery
Reads the Composer classmap to find all classes with a given attribute.

Route Discovery

Single attribute, live endpoint

This page exists because the payload declared the route directly in PHP and the handler only had to return the response resource.

GET /demo/routing/basic Resolved route
200 OK Status
Payload owns route One handler method Typed response No central routes file
#[AsProtectedPayload] #[AsPublicPayload] #[AsServicePayload] env::VAR_NAME::/default/path responseWith ClassDiscovery path methods

Verified against Semitexa Ultimate 2026.09.19.1020

Basic Route

A single access attribute on a PHP class creates a fully routed HTTP endpoint — no XML, no YAML, no config files. Access is explicit at the type level: every payload picks one of #[AsPublicPayload], #[AsProtectedPayload], or #[AsServicePayload].

HTTP request lifecycleHTTP request lifecycle. HTTP request: Method, path, headers. Payload: Route and input contract. Handler: Runs the use case. Resource: Shapes the response. Template: Produces final HTMLmatch and hydratedispatchpopulaterenderHTTP requestMethod, path, headersPayloadRoute and input contractHandlerRuns the use caseResourceShapes the responseTemplateProduces final HTML
HTTP request lifecycle

How it works

The framework scans the Composer classmap for classes carrying any of the three access attributes, extracts path and method metadata, resolves env:: placeholders if present, and registers routes at boot. The route compiler then turns path patterns into optimized regex matchers cached in memory.

Why this matters

Keeping route definitions co-located with their request DTOs means a reader can understand what an endpoint accepts and where it lives by reading a single file. The access attribute on the same line declares the security stance — anonymous, user-authenticated, or service-domain — so route review and security review collapse into one read. env:: syntax lets operations move a route without reopening PHP code when deployment topology demands it.

© Harold Abelson: "Programs must be written for people to read, and only incidentally for machines to execute."

Payload Trusted input boundary
<?phpdeclare(strict_types=1);namespace App\Application\Payload\Routing;use App\Application\Resource\Page\BasicPageResource;use Semitexa\Core\Attribute\AsPublicPayload;#[AsPublicPayload(    path: '/catalog',    methods: ['GET'],    responseWith: BasicPageResource::class,    produces: ['text/html'],)]final class BasicRoutePayload{}

How it works

The framework scans the Composer classmap for classes with #[AsPayload], extracts path and method metadata, resolves env:: placeholders if present, and registers routes at boot. The route compiler then turns path patterns into optimized regex matchers cached in memory.

Why it matters

Keeping route definitions co-located with their request DTOs means a reader can understand what an endpoint accepts and where it lives by reading a single file. At the same time, env:: syntax lets operations move a route without reopening PHP code when deployment topology demands it.

Key concepts

#[AsPayload]
Attribute that marks a class as a request DTO and declares its HTTP route.
env::VAR_NAME::/default/path
Special attribute syntax that lets a payload read its route path, name, or other metadata from .env with a safe default fallback.
responseWith
Links the payload to the Resource DTO that shapes the response.
ClassDiscovery
Reads the Composer classmap to find all classes with a given attribute.

Support Semitexa
Built for developers who prefer control over magic. Your support helps keep it fast, open, and evolving.

Donate via PayPal