diff --git a/framework/core/src/Api/Middleware/ReadJsonParameters.php b/framework/core/src/Api/Middleware/ReadJsonParameters.php new file mode 100644 index 000000000..6395d805d --- /dev/null +++ b/framework/core/src/Api/Middleware/ReadJsonParameters.php @@ -0,0 +1,24 @@ +getHeaderLine('content-type'), 'application/vnd.api+json')) { + $input = json_decode($request->getBody(), true); + + foreach ($input as $name => $value) { + $request = $request->withAttribute($name, $value); + } + } + + return $out ? $out($request, $response) : $response; + } +} diff --git a/framework/core/src/Api/routes.php b/framework/core/src/Api/routes.php index af64c7145..4e64707dd 100644 --- a/framework/core/src/Api/routes.php +++ b/framework/core/src/Api/routes.php @@ -1,6 +1,6 @@ app->make($class); $actor = $this->app->make('Flarum\Support\Actor'); - if (str_contains($httpRequest->getHeaderLine('content-type'), 'application/vnd.api+json')) { - $input = json_decode($httpRequest->getBody(), true); - } else { - $input = $httpRequest->getAttributes(); - } - $input = array_merge($input, $routeParams); - - $request = new ApiRequest($input, $actor, $httpRequest); + $input = array_merge($httpRequest->getAttributes(), $routeParams); + $request = new Request($input, $actor, $httpRequest); return $action->handle($request); };