softonic/laravel-request-accept-json-middleware

Laravel middleware to add Accept application/json header to requests
55,903 4
Install
composer require softonic/laravel-request-accept-json-middleware
Latest Version:5.0.0
PHP:>=8.5
Laravel:12
License:Apache-2.0
Last Updated:Jan 12, 2026
Links: GitHub  ·  Packagist
Maintainer: Joskfg

Laravel request accept json middleware

Latest Version Software License Build Status Coverage Status Quality Score Total Downloads Average time to resolve an issue Percentage of issues still open

This middleware adds the ability to automatically add the Accept application/json header to every request if it was not provided.

Requirements

  • PHP >= 8.5
  • Laravel 12.x

Installation

Via composer:

composer require softonic/laravel-request-accept-json-middleware

Documentation

To use the middleware register it in app/Http/Kernel.php

    protected $middleware
        = [
            ...
            RequestAcceptJson::class,
            ...
        ];

From now on the header Accept: application/json will be automatically added to every request.

Testing

softonic/laravel-request-accept-json-middleware has a PHPUnit test suite, code style compliance check using PHP CS Fixer, and static analysis using PHPStan.

To run the tests, run the following command from the project folder:

$ docker compose run --rm test

To run PHPUnit only:

$ docker compose run --rm phpunit

To check code style:

$ docker compose run --rm php composer run phpcs

To fix code style issues:

$ docker compose run --rm fixcs

To run static analysis:

$ docker compose run --rm php composer run phpstan

License

The Apache 2.0 license. Please see LICENSE for more information.

Related Packages

open-cetacean/laravel-json-header

Middleware to force Laravel API group to JSON header

757 0
tucker-eric/laravel-xml-middleware

A Laravel Middleware to accept XML requests

1,193,749 18
lara-middleware/request-id

Laravel 5 RequestId Middleware

14 2

Version History

Version Released PHP Laravel License
5.0.0 >=8.5 ^12.0 Apache-2.0
4.0.0 >=8.2 ^11.0 Apache-2.0
3.2.0 >=7.2 ^8.0 || ^9.0 || ^10.0 Apache-2.0
3.1.1 >=7.2 ^7.0 || ^8.0 || ^9.0 Apache-2.0
3.1.0 >=7.2 ^7.0 || ^8.0 Apache-2.0