Getting Started#
Start here if you want a working Webrick app with current APIs and production-friendly defaults.
What you’ll set up#
Install Webrick with Composer
Boot
RouterKernel::bootWithRegistrar(...)Register routes through
Infocyph\Webrick\Router\Facade\Router as RouteEnable URL generation and signed URLs
Add middleware aliases where string middleware is needed
Build route cache for deployment
Install#
composer require infocyph/webrick
Boot the kernel#
use Infocyph\Webrick\Request\Request;
use Infocyph\Webrick\Response\Emitter\AutoEmitter;
use Infocyph\Webrick\Response\Response;
use Infocyph\Webrick\Router\Definition\Registrar;
use Infocyph\Webrick\Router\Facade\Router as Route;
use Infocyph\Webrick\Router\Kernel\RouterKernel;
use Infocyph\Webrick\Router\Matching\ShardedMatcher;
use Psr\Log\NullLogger;
$kernel = RouterKernel::bootWithRegistrar(
log: new NullLogger(),
matcher: ShardedMatcher::make(__DIR__ . '/.route-cache'),
register: static function (Registrar $registrar): void {
unset($registrar);
Route::get('/', fn() => Response::plaintext('Hello Webrick', 200), 'home');
},
routeCache: __DIR__ . '/.route-cache',
registrarOptions: [
'exposeUrlServices' => true,
'signKey' => $_ENV['WEBRICK_SIGN_KEY'] ?? 'dev-key-change-me',
'signedDefaultTtl' => 300,
'urlBaseUri' => $_ENV['WEBRICK_URL_BASE_URI'] ?? 'http://localhost',
],
);
(new AutoEmitter())->emit($kernel->handle(Request::fromGlobals()));
First route helpers#
use Infocyph\Webrick\Router\Facade\Router as Route;
$url = Route::urlFor('home');
$signed = Route::signedUrlFor('home');
$temp = Route::temporaryUrlFor('home', ttl: 300);
Route cache build#
php ./webrick route:cache --matcher=sharded --cache=.route-cache --routes=routes.php
Next steps#
Read
quickstartfor a fuller bootstrap with aliases and middleware.Read
guides/urlsfor the richer signed URL surface.Read
reference/route-cachefor matcher and artifact details.