Home > front end >  append a request body to vertx request
append a request body to vertx request

Time:05-25

IN my java sample code of a vertex URL instance below, The URL returns a json request when called. I am trying to append a request body to the URL but I am stuck. Here is a sample snippet

Route handler2 = router
                .post("/get-a-file")
                .consumes("*/json")
                .handler(routingContext -> {
                    HttpServerResponse response = routingContext.response();
                    response.setChunked(true);
                    response.write("bla bla bla...");
                    response.end();
                });

Just getting my hands on vert.x. Do assist

CodePudding user response:

For request bodies in Vert.x your route needs a BodyHandler. You should add it before your own handler so that the request body is already there when your business logic runs.

Your code should look similar to this:

...
.consumes("*/json")
.handler(BodyHandler.create())
.handler(routingContext -> ...

Now you can access the body on routingContext and map it to your DTO.

  • Related