Unable to access request body using getBodyAsJson() in Vert.X 3.0.0
Asked Answered
P

2

19

I am using Vert.x 3.0.0-milestone5, to develop a sample web application. Everything is working fine as far as the routing is concerned, but I am not able to access request parameters using routingContext.getBodyAsJson() or routingContext.getBody() or routingContext.getBodyAsString(). Here is the complete description.

Physiologist answered 16/6, 2015 at 4:38 Comment(2)
Ok got it. we need to create BodyHandler using router.route().handler(BodyHandler.create()). Thanks to Tim Fox linkedin.com/in/timfox.Physiologist
vertx.io/blog/some-rest-with-vert-xSpirula
T
37

If you want to use

routingContext.getBody();
routingContext.getBodyAsJson();

You first need to add a body handler like below:

router.route().handler(BodyHandler.create());
Turkestan answered 15/5, 2016 at 0:48 Comment(0)
B
0

In new version of Vert.x these methods are Deprecated: link

So, you need to use body();. Or add this tag before @Deprecated

@Deprecated
routingContext.getBody();
routingContext.getBodyAsJson();

Reference: Here

Barrows answered 22/2, 2023 at 18:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.