From a5c5518a12e7e536e0bed652367cb576516833c9 Mon Sep 17 00:00:00 2001 From: Nabeel Shahzad Date: Thu, 28 Dec 2017 22:50:07 -0600 Subject: [PATCH] Add middleware to set Content-type to application/json on all API requests --- app/Http/Kernel.php | 2 ++ app/Http/Middleware/JsonResponse.php | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 app/Http/Middleware/JsonResponse.php diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php index 660a0f8a..a7fbe51c 100755 --- a/app/Http/Kernel.php +++ b/app/Http/Kernel.php @@ -37,6 +37,7 @@ class Kernel extends HttpKernel 'api' => [ 'throttle:60,1', 'bindings', + 'json', ], ]; @@ -54,6 +55,7 @@ class Kernel extends HttpKernel 'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class, 'can' => \Illuminate\Auth\Middleware\Authorize::class, 'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class, + 'json' => \App\Http\Middleware\JsonResponse::class, 'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class, #'role' => \Laratrust\Middleware\LaratrustRole::class, #'permission' => \Laratrust\Middleware\LaratrustPermission::class, diff --git a/app/Http/Middleware/JsonResponse.php b/app/Http/Middleware/JsonResponse.php new file mode 100644 index 00000000..5eb06262 --- /dev/null +++ b/app/Http/Middleware/JsonResponse.php @@ -0,0 +1,18 @@ +headers->set('Content-Type', 'application/json'); + return $response; + } +}