mini\Controller\AbstractController::respond() Method

protected

Signature

protected function respond(mixed $data, int $status = 200, array $headers = array (
)): Psr\Http\Message\ResponseInterface

Parameters

Name Type Default Description
$data mixed required Documentation missing
$status int 200 Documentation missing
$headers array array ( ) Documentation missing

Returns

Psr\Http\Message\ResponseInterface

Documentation

Content negotiation response

Checks Accept header to determine response format:

  • application/json → JSON response
  • text/html → Renders view if exists, otherwise JSON
  • wildcard or empty → Prefers HTML if view exists, otherwise JSON

This enables API-first development with progressive HTML enhancement.

Source

src/Controller/AbstractController.php:117-132