Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message
Laravel Request Accept Json Middleware

Laravel Request Accept Json Middleware Laravel Package

softonic/laravel-request-accept-json-middleware

Laravel middleware that automatically sets the Accept: application/json header on incoming requests, ensuring your API returns JSON responses even when clients omit it. Easy to register globally or per route group, with no changes required to existing controllers or routes.

View on GitHub
Deep Wiki
Context7

Laravel middleware to add Accept application/json header to requests

Frequently asked questions about Laravel Request Accept Json Middleware
What does softonic/laravel-request-accept-json-middleware do?
It is a Laravel middleware that adds the Accept: application/json header to incoming requests, so your API returns JSON even when clients omit that header. It is useful when controllers and form requests rely on Laravel's content negotiation. No changes to existing controllers or routes are required.
How do I install softonic/laravel-request-accept-json-middleware?
Install it with Composer using composer require softonic/laravel-request-accept-json-middleware. Version 5.0 requires Laravel ^12.0 and PHP ^8.5, so confirm your application stack first. Then register the middleware globally or on your API route group.
How do I register this Accept application/json middleware in Laravel?
In Laravel 12, register it in bootstrap/app.php using the withMiddleware callback, appending it to the global stack or to the api group. If you are on an older Laravel line with the HTTP Kernel, add it to the appropriate middleware array. Registering it only on API routes is usually the safer choice.
Should I add the middleware globally or only to API route groups?
Prefer the API route group so HTML, session, and redirect responses on web routes are not forced into JSON negotiation. Global registration can change error pages and browser-facing behavior. Use global registration only if the entire application is an API.
Which Laravel and PHP versions does version 5.0 support?
Version 5.0 requires Laravel ^12.0 and PHP ^8.5 and is explicitly not backward compatible with earlier support lines. If you are on Laravel 11 or older, you cannot use 5.0 until the framework and runtime are upgraded. Composer will fail the resolve if those floors are not met.
Does the middleware override an Accept header already sent by the client?
The middleware's purpose is to ensure the request carries Accept: application/json, so it sets that header on the request. If your clients send different Accept values and you depend on them, review the package source and tests before adopting it. For conditional behavior, a small custom middleware may be safer.
How do I test that the middleware forces JSON responses?
Write a Laravel feature test that calls an API route without an Accept header and asserts the response is JSON, for example with assertJson or by checking the content type. Also test a route outside the middleware group to confirm it is unaffected. Running the suite on Laravel 12 and PHP 8.5 matches the supported matrix.
What are alternatives to this Laravel Accept header middleware?
You can make API clients send Accept: application/json by default, add a custom middleware that sets the header, or configure your HTTP client defaults. Some teams handle this in route middleware or a response macro. This package simply packages that behavior as a reusable Composer dependency.
Is softonic/laravel-request-accept-json-middleware safe for production?
It is a small request middleware, so runtime overhead is low, but treat version 5.0 as a platform-support bump: verify the 4.x to 5.0 diff and confirm the break is constraint-only. Pin an explicit ^5.0 constraint and check that 4.x still receives security fixes while you migrate. Canary one service before rolling it across the portfolio.
How do I upgrade from version 4.x to 5.0?
Upgrade your application to Laravel 12 and PHP 8.5 first, then change the Composer constraint to ^5.0. Because 5.0 declares no backward compatibility, review the public API diff and release notes before merging. If you cannot meet the runtime floor, stay on 4.x and track its EOL date.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
store-doc/laravel-storage-driver
plus-it/laravel-translation-manager
diephp/perhaps
diephp/telegraph
osmaviation/spreadsheet
microsoft/fluentui-system-icons
mmccook/php-json-canonicalization-scheme
middlewares/firewall
qubiqx/montapacking
nyoncode/laravel-package-console
pnscripts/filament-broadquill-lite
pnscripts/laravel-sentfold-lite
vleap/mx-sdk-laravel-internal
twidpay/utils
htetmyathlaing/scout-elasticsearch-driver
artisan-toolbox/front-awesome
ls/client-assistant
users-au/laravel-client
cgv/localized-resource
noith/settings