How I can use getBodyParsed() with put or Patch mathod?
When I do
bodyParams=$request->getParsedBody();
return $response->write(json_encode($bodyParams));
it returns null with PATCH or PUT.
As far as I know the Slim $request->getParsedBody()
method is only for the http POST
method and not for PUT/PATCH methods.
More details: https://github.com/slimphp/Slim/issues/1396
But you could implement your own PUT/PATCH middleware:
$app->add(function ($request, $response, $next) {
if($request->isPatch() || $request->isPut()) {
parse_str($request->getBody()->__toString(), $data);
$request = $request->withParsedBody($data);
}
return $next($request, $response);
});