Response
Every Response constructor returns a value object — nothing is echoed or exits at
construction time. Your action returns it; Route::dispatch() hands it back to
public/index.php, which calls ->send() exactly once.
Constructors
Response::json(mixed $data, int $status = 200): self
Response::htm(string $html, int $status = 200): self // note: htm(), not html()
Response::text(string $text, int $status = 200): self
Response::download(string $path, ?string $name = null): self
Response::redirect(string $to, int $status = 302): self
Response::noContent(): self
Response::stream(callable $callback): self
A controller returning a plain PHP array instead of a Response is also valid —
Route converts it to a JSON response automatically.
Instance methods
$response->status(): int
$response->header(string $name): ?string
$response->withHeader(string $name, string $value): self // returns a new instance
$response->content(): string
$response->send(): void
PSR-7 bridge
$response->toPsr7(): Psr\Http\Message\ResponseInterface
There's no fromPsr7() — your application code is always the one producing a Response, never converting one in from elsewhere.
Next steps
- Request/Response Lifecycle — where
send()fits end to end. - Request — the other half of every request.