Skip to content

Add JSON exception rendering helper for API routes#60208

Open
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:api-json-rendering-for-install-api
Open

Add JSON exception rendering helper for API routes#60208
LucasCavalheri wants to merge 1 commit into
laravel:13.xfrom
LucasCavalheri:api-json-rendering-for-install-api

Conversation

@LucasCavalheri
Copy link
Copy Markdown

This PR adds a small DX improvement for API-first Laravel applications.

It introduces a new convenience method:

$exceptions->shouldRenderJsonForApiRoutes();

which internally configures exception rendering for api/* routes using the existing shouldRenderJsonWhen(...) API.

The install:api command/stubs have also been updated to automatically enable JSON exception rendering for API routes in newly generated applications.

This helps avoid a common source of confusion when testing API routes with tools such as Postman, Insomnia, or curl without manually sending the Accept: application/json header.

The implementation is intentionally minimal and does not mutate the incoming request or alter existing expectsJson() behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant