Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1
Automatically always return a response in JSON format
License
TheDragonCode/laravel-json-response
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Automatically always return a response in JSON format
To get the latest version ofLaravel Json Response, simply require the project usingComposer:
$ composer require dragon-code/laravel-json-response
Or manually updaterequire block ofcomposer.json and runcomposer update.
{"require": {"dragon-code/laravel-json-response":"^1.0" }}- Replace
"andrey-helldar/laravel-json-response": "^1.0"with"dragon-code/laravel-json-response": "^2.0"in thecomposer.jsonfile; - Call the
composer updateconsole command.
After you've installed the package via composer, you're done. There's no step two.
This package will automatically register theDragonCode\LaravelJsonResponse\Middlewares\SetHeaderMiddleware middleware in theweb andapi groups, if theyexist. The middleware will add a headerAccept that will effectively convert all responses to JSON format. This header will apply to all responses.
Why are my error messages not being converted to JSON?
This is a feature of theLaravel architecture. The package makes corrections during the loading of the framework and it stores its state internally, and in case of an error, it takes the value of the request from the outside. Therefore, the error text is returned in html format.
To fix this problem, you need to explicitly pass theAccept: application/json header in requests, or use thedragon-code/api-response package.
About
Automatically always return a response in JSON format
Resources
License
Contributing
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Contributors5
Uh oh!
There was an error while loading.Please reload this page.