Stop Slim parsing the body

Is there any way to tell Slim 4 to not automatically parse the body of a POST request in “application/x-www-form-urlencoded” format?

I’m asking because I had to implement a middleware to parse the same for a PUT request, which is not automatically done, and ended up moving to JSON instead. So finally I have a middleware which parses the body if in “application/json” format.

The problem is that now $request->getParsedBody() returns the parsed body no matter if in urlencode or JSON format (because some underlying middleware is parsing the body if urlencoded). So the APIs now can understand both.

I’d like to limit the APIs to accept requests with bodies only in JSON format. Is it possible to disable the default behavior?

You can always ignore $request->getParsedBody(), inject (string) $request->getBody() into your custom parser and only parse the body where you need to.

I think the result of getParsedBody() will be different for each PSR-7 implementation so you can try to see if there is one that fits your app better.