1

What is best method to implement ReST based Web Services in Java. Should I go for JAX-RS implementations. Or should I go for Spring MVC or directly via Servlets? Well what is the actual difference with these?

Mobiz Tech Team
  • 182
  • 3
  • 12
  • 1
    Have a look at the following similar questions: http://stackoverflow.com/questions/1495813/easiest-frameworks-to-implement-java-rest-web-services and http://stackoverflow.com/questions/1069772/can-anyone-recommend-a-java-web-framework-that-is-based-on-mvc-and-supports-rest – Subir Kumar Sao May 11 '12 at 07:18

5 Answers5

3

I prefer to use JAX-RS, it requires to write less for the same result.

Spring MVC:

@Controller
@RequestMapping(value = "/convert", produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
public class ConversionController extends BaseController {

    @RequestMapping(method = RequestMethod.POST, produces = MediaType.APPLICATION_XML_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
    @ResponseBody
    public String jsonToXml(@RequestBody String jsonString) throws JSONException {
        //method body
    }
}

JAX-RS:

@Path("/venue")
@Consumes(Const.FORMAT_APPLICATION_JSON_UTF8)
@Produces(Const.FORMAT_APPLICATION_JSON_UTF8)
public class ConversionController 
{
    @POST
    public Venue addVenueToDatastore(Venue aVenue) {
         //method body
    }
}
yatul
  • 1,103
  • 12
  • 27
1

You should use JAX-RS implementation. I recommend Jersey or Resteasy. Spring MVC is a bit verbose.

Konstantin V. Salikhov
  • 4,554
  • 2
  • 35
  • 48
0

I use VRaptor MVC framework in order to build RESTful and service oriented applications in a simpler way, just like I was writing common web applications... Might worth taking a look at the ten minutes guide

Renato Gama
  • 16,431
  • 12
  • 58
  • 92
0

I have developed the REST services in Spring MVC as well as Jersey. If you only need to create REST api use JERSEY and if your project is more then REST Api you can use Spring MVC . Some useful links are as follows -

http://www.ibm.com/developerworks/web/library/wa-aj-tomcat/

http://jersey.java.net/

kundan bora
  • 3,821
  • 2
  • 20
  • 29
0

I'm using Play Framework for Web Service. Here is some example how to do it.

Crazenezz
  • 3,416
  • 6
  • 31
  • 59