Getting Started
Routing
Strata uses a compiled Radix router with zero regex on the hot path. Routes are explicit, type-safe, and PSR-7 native.
Basic Routes
Define routes on the Router instance. Use closures for handlers.
<?php
use App\Router;
use App\Request;
use App\User;
$router = new Router();
$router->get('/', fn() => 'Home');
$router->post('/users', fn(Request $r) => User::create($r->json()));
$router->put('/users/{id}', function($id) { return "Update user $id"; });
$router->delete('/users/{id}', function($id) { return "Delete user $id"; });
$router->run();
?>
Route Parameters
Parameters are type-hinted. Strata auto-casts them.
<?php
$router->get('/users/{id}', function(int $id) {
return "User $id";
});
$router->get('/users/by-email/{email}', function(string $email) {
return User::findByEmail($email);
});
?>
Type Safety: If
/users/abc is hit, Strata returns 404 before your code runs. No is_numeric() checks needed.Route Groups
Group routes to apply prefixes. Add middleware if your project defines it.
<?php
$router->group('/api', function($api) {
$api->group('/v1', function($v1) {
$v1->get('/users', function() { return User::all(); });
$v1->post('/users', function(Request $r) { return User::create($r->json()); });
});
});
?>
This creates /api/v1/users.
Fallback Route
Catch anything that didn’t match.
<?php
$router->fallback(function() {
http_response_code(404);
return 'Not Found';
});
?>