Framework/src/Http/ApiResponseFactoryInterface.php
2025-12-14 17:10:01 -06:00

31 lines
918 B
PHP

<?php
declare(strict_types=1);
namespace Phred\Http;
use Psr\Http\Message\ResponseInterface;
/**
* Abstraction for producing API responses.
* Implementations should honor the configured API format (REST or JSON:API).
*/
interface ApiResponseFactoryInterface
{
/**
* 200 OK with serialized payload.
* $context may contain format-specific hints (e.g., JSON:API resource type, includes, fields).
*/
public function ok(mixed $data, array $context = []): ResponseInterface;
/**
* 201 Created with Location header and serialized payload.
*/
public function created(string $location, mixed $data, array $context = []): ResponseInterface;
/**
* Generic JSON error payload (format-specific). Not a replacement for Problem Details middleware.
*/
public function error(int $status, string $title, ?string $detail = null, array $meta = []): ResponseInterface;
}