# Using getParsedBody in middleware

**URL:** <https://discourse.slimframework.com/t/using-getparsedbody-in-middleware/2687>\
**Category:** Questions\
**Created:** [September 23, 2018, 1:29pm UTC](https://discourse.slimframework.com/t/using-getparsedbody-in-middleware/2687 "2018-09-23T13:29:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ikbenkwik](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@ikbenkwik](https://discourse.slimframework.com/u/ikbenkwik)\
**Post date:** [September 23, 2018, 1:29pm UTC](https://discourse.slimframework.com/t/using-getparsedbody-in-middleware/2687/1 "2018-09-23T13:29:45Z")

</div>

In a route i’m able to use $request-\>getParsedBody() to obtain values from the body. I use the values to do some validations. I would like to move these validations to middleware. Now when i access $request-\>getParsedBody() within my middleware, it returns NULL.

What is going on here? Is it not possible to read the body in middleware?

---

<div class="post-metadata">

**Author:** ![SVL](https://avatars.discourse-cdn.com/v4/letter/s/848f3c/32.png) [@SVL](https://discourse.slimframework.com/u/SVL)\
**Post date:** [September 23, 2018, 1:50pm UTC](https://discourse.slimframework.com/t/using-getparsedbody-in-middleware/2687/2 "2018-09-23T13:50:18Z")

</div>

Check the config of your app and make sure determineRouteBeforeAppMiddleware is set and true:

`'determineRouteBeforeAppMiddleware' => true`

Then in your middleware (assuming JSON here):

```
$requestBody = $request->getBody();
$requestObject = json_decode($requestBody);

// code to validate or alter $requestObject 

$request = $request->withParsedBody($requestObject);
return $next($request, $response);
```

---

<div class="post-metadata">

**Author:** ![ikbenkwik](https://avatars.discourse-cdn.com/v4/letter/i/96bed5/32.png) [@ikbenkwik](https://discourse.slimframework.com/u/ikbenkwik)\
**Post date:** [September 23, 2018, 2:21pm UTC](https://discourse.slimframework.com/t/using-getparsedbody-in-middleware/2687/3 "2018-09-23T14:21:30Z")

</div>

Thanks for your reply. It works great for me!
