Friday, November 27, 2015

Setting basic response http headers for REST resources on a simple Vertx Rest based app #vertxio #vertx

I am new to Vert.x but as a Java developer (die hard) I find it much more enjoyable and promising comparing to NodeJS or whatever - Reactor based frameworks/libraries. So I was going through implementing a very simple Restful API, using Vert.x.

My problem for today is that I wanted to include some certain HttpHeaders in most (all) of my , responses. For example set the Content-type to "application/json". In the future maybe add some others.

I was kind of wondering around as a Vert.x newbie, then I kind of realized that what is was eventually suggested in this blog post (See the use of BodyHandler) would actually work for me.

So I had my main VertxMain java app where I register my MyWebVerticleApp.

Then I have created a small handler, I call it BaseResponseHandler, that eventually adds the HttpHeader in my responses.

Then in my MyWebVerticle I just register the handler to be invoked all the time, in the router chaining.

No comments:

Post a Comment