https://github.com/softonic/laravel-request-accept-json-middleware
Laravel middleware to add Accept application/json header to requests
https://github.com/softonic/laravel-request-accept-json-middleware
accept json laravel laravel-middleware middleware
Last synced: 5 months ago
JSON representation
Laravel middleware to add Accept application/json header to requests
- Host: GitHub
- URL: https://github.com/softonic/laravel-request-accept-json-middleware
- Owner: softonic
- License: other
- Created: 2019-07-26T14:02:48.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2025-01-16T14:46:15.000Z (over 1 year ago)
- Last Synced: 2025-04-10T22:44:10.229Z (about 1 year ago)
- Topics: accept, json, laravel, laravel-middleware, middleware
- Language: PHP
- Size: 15.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Codeowners: CODEOWNERS
Awesome Lists containing this project
README
Laravel request accept json middleware
=====
[](https://github.com/softonic/laravel-request-accept-json-middleware/releases)
[](LICENSE.md)
[](https://github.com/softonic/laravel-request-accept-json-middleware/actions)
[](https://scrutinizer-ci.com/g/softonic/laravel-request-accept-json-middleware/code-structure)
[](https://scrutinizer-ci.com/g/softonic/laravel-request-accept-json-middleware)
[](https://packagist.org/packages/softonic/laravel-request-accept-json-middleware)
[](http://isitmaintained.com/project/softonic/laravel-request-accept-json-middleware "Average time to resolve an issue")
[](http://isitmaintained.com/project/softonic/laravel-request-accept-json-middleware "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](https://phpunit.de) test suite, code style compliance check using [PHP CS Fixer](https://cs.symfony.com/), and static analysis using [PHPStan](https://phpstan.org/).
To run the tests, run the following command from the project folder:
``` bash
$ docker compose run --rm test
```
To run PHPUnit only:
``` bash
$ docker compose run --rm phpunit
```
To check code style:
``` bash
$ docker compose run --rm php composer run phpcs
```
To fix code style issues:
``` bash
$ docker compose run --rm fixcs
```
To run static analysis:
``` bash
$ docker compose run --rm php composer run phpstan
```
License
-------
The Apache 2.0 license. Please see [LICENSE](LICENSE) for more information.
[PSR-12]: https://www.php-fig.org/psr/psr-12/
[PSR-4]: https://www.php-fig.org/psr/psr-4/