Requests and responses
The classes an endpoint takes and returns. Resources are Laravel's own JsonApiResource; Fusion Stack adds a form request base class and plain JSON responses for actions.
Resources
Return an Illuminate\Http\Resources\JsonApi\JsonApiResource from resource endpoints, or a collection of them from an ApiQuery. It lists the model's attributes and relationships:
use Illuminate\Http\Resources\JsonApi\JsonApiResource;
final class OrderResource extends JsonApiResource
{
public array $attributes = ['reference', 'status', 'total_cents', 'currency', 'created_at'];
public array $relationships = ['customer'];
}{
"data": {
"id": "15",
"type": "orders",
"attributes": { "reference": "ORD-ZAJZUXSU", "status": "paid", "total_cents": 31428, "currency": "GBP", "created_at": "2026-12-01T11:59:25.000000Z" }
}
}Describe its fields for the API reference with #[Describe]. For the document format, see JSON:API.
ApiRequest
FusionStack\Laravel\Http\ApiRequest is a FormRequest for API input. Write its rules against the latest version's field names: bodies from older clients are migrated by their version changes before validation, and validation errors are rendered with the client's own field names.
use FusionStack\Laravel\Http\ApiRequest;
final class StoreOrderRequest extends ApiRequest
{
public function rules(): array
{
return [
'data.type' => ['required', 'in:orders'],
'data.attributes.total_cents' => ['required', 'integer', 'min:0'],
'data.attributes.currency' => ['required', 'string', 'size:3'],
'data.relationships.customer.data.id' => ['required', 'exists:customers,id'],
];
}
}A failed rule is a 422 validation_failed with one error per message, each pointing at its field, such as /data/attributes/total_cents.
| Method | What it returns |
|---|---|
version() | The ApiVersion the client is pinned to, or null while versioning is off. |
A describe() method adds descriptions and examples of its fields to the API reference; see #[Describe].
ApiResponse
FusionStack\Laravel\Http\ApiResponse builds plain JSON responses for action endpoints, such as POST /v1/orders/{order}/resend-confirmation. Version changes transform them as they do resources; in plain JSON, the attributes are the top-level keys.
use FusionStack\Laravel\Http\ApiResponse;
return ApiResponse::accepted(['status' => 'queued'], location: "/v1/orders/{$order->id}");| Method | Response |
|---|---|
ok() | 200 with a JSON body. An empty body is {}. |
accepted() | 202 for queued work, with a Location header where the client can check on it, when given. |
noContent() | 204 with no body. |
Each also takes extra headers.