Over a million developers have joined DZone.

RESTEasy's @Form

· Java Zone

What every Java engineer should know about microservices: Reactive Microservices Architecture.  Brought to you in partnership with Lightbend.

@Form is one of RESTEasy's best features. It encapsulates any set of inputs - path params, query params, form params, headers, cookies and PUT/POST body. NOTE: @Form does not ONLY encapsulate HTML Form input, although it can as described in my article about integrating RESTEasy with Spring MVC

Here's how it's used in an application:

public class MyForm {

   @FormParam("stuff")
   private int stuff;


   @HeaderParam("myHeader")
   private String header;


   @PathParam("foo")
   public void setFoo(String foo) {...}
}

@POST
@Path("/myservice")
public void post(@Form MyForm form) {...}

 

I've had HTTP input reuse in every big HTTP application that I've built in 3 organizations. 2 of the organizations used RESTEasy, and the results were a lot cleaner than the 3rd org with the use of @Form than with some of the "reuse hacks" I've had to do when using Jersey. Here are some other benefits I've had from @Form:

  • Input processing Logic: custom conversion, multi-variable processing (if param X isn't there, then param Y should be used in conjunction with header Z).
  • Content based security
  • Integration with JSR 303/Bean Validation (you can't use it unless you have a bean...). The processing happened via a RESETEasy interceptor. IMHO, the end result was elegant and simple.

I really hope that this feature gets into JAX-RS 2.0, although I think that the name would have to be more expressive than @Form.

 

From http://www.jroller.com/Solomon/entry/resteasy_s_form

Microservices for Java, explained. Revitalize your legacy systems (and your career) with Reactive Microservices Architecture, a free O'Reilly book. Brought to you in partnership with Lightbend.

Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}