Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to write a RESTful JSON service in Java

Tags:

java

json

rest

Here is my requirement:

  1. I have a simple table in mysql(Consider any table with a few fields)
  2. I need to write a simple RESTFUL JSON webservice in Java that performs CRUD operations on this table.

I tried searching on the net for some comprehensive example for this but could not find any. Can anyone help?

like image 410
wantobegeek Avatar asked Oct 01 '11 19:10

wantobegeek


People also ask

What is JSON RESTful web service?

Java JSON RESTful Web Service Example Posted by: Saurabh Arora in restMarch 30th, 20160Views In this example we shall learn implementing RestfulWeb Service in Java where the data interchange format shall be JSON. 1. Introduction to RESTful Web Services RESTful Web Services follow RESTarchitecture which stands for REpresentational State Transfer.

How do I create a RESTful service in NetBeans?

First, fire up Netbeans and create a new Maven Web Application project. Give it a name of you choosing. Right off the bat, create a web.xml file by right clicking on the project and creating a new Standard Deployment Descriptor. This is the configuration file for the RESTful service mapping.

How do I get JSON response from a web service?

JSON Response in Web Service. To change a web service that is already written to provide a XML response or to create a new one, we need to add just two things. Use @Produces annotation and add the MIME type application/json. Add dependent JAR files to produce JSON response.

How to get XML response from a RESTful web service?

We need to add a “Header” with the request to the web service. Same RESTful web service is capable of producing XML response as we have added XML MIME type also in @Produces annotation.


1 Answers

Jersey is a JAX-RS implementation for building RESTful webservices.

Start with their tutorial. It's pretty easy.

http://jersey.java.net/nonav/documentation/latest/getting-started.html

Edit: Also, there's a great O'Riley book on the subject (shocking, I know); RESTful Java with JAX-RS

like image 111
Brian Roach Avatar answered Oct 12 '22 22:10

Brian Roach