Introduction to RESTful Web Services—A JAX-RS Specification
Learn about web services, what they are, what they're used for, different types of web services, and their advantages over other specifications.
Join the DZone community and get the full member experience.Join For Free
In this article, we will learn about the different types of web services. Further, we will concentrate on RESTful web services.
An inter-operable service hosted & up-running over the web which could be accessed by different independent clients like web browser.
Types of Web Services
- REST (Representational State Transfer)
- SOAP (Simple Object Access Protocol)
JAX-RS 2.0 specification supports implementation of RESTful web services.
Different vendor implementation for this type are:
Oracle Jersey (Prior 2.x)
Glassfish Jersey (2.x)
- JAX-WS 2.0 specification supports implementation of SOAP-based web services.
- Different vendor implementation for this type are:
- JAX-WS viz., Top-down and Bottom-up approach
- Apache Axis2
Source: BenchResources.net team
In this particular article, we will discuss and learn JAX-RS 2.0 specification based Restful web service. Later in the upcoming articles, we will use Apache’s CXF (Celtix + XFire) to implement demo examples.
RESTful Web Services
In the REST of World, you call everything as resource and it is uniquely identified using URI i.e.; Uniform Resource Identifier. REST server and clients interacts using stateless HTTP protocol via four broadly classified HTTP verbs viz.
- POST - to CREATE/insert resource
- GET - to READ/select/retrieve internal resource
- PUT - to UPDATE/modify the resource
- DELETE - to DELETE/remove internal resource representation
Note: That forms CRUD
Relationships Between SQL and HTTP Verbs
Formats Supported in RESTful Web Services
Advantages of RESTful Web Services
- REST architectural pattern is basically lightweight in nature. So, when you have bandwidth constraints then prefer REST web service.
- Easy and fast to develop.
- Top sites like Twitter, Yahoo uses this pattern.
- Most social networking sites like Facebook.com uses REST web services.
- Mobile App development growing rapidly and for their server interaction, it uses this REST pattern as it is faster in processing request/response data.
These are the most commonly used JAX-RS Annotations, when developing REST based web service. In the upcoming articles, we will understand & use these annotations and implement demo examples.
- @Path (javax.ws.rs.Path)
- @GET (javax.ws.rs.GET)
- @POST (javax.ws.rs.POST)
- @PUT (javax.ws.rs.PUT)
- @DELETE (javax.ws.rs.DELETE)
- @PathParam (javax.ws.rs.PathParam)
- @QueryParam (javax.ws.rs.QueryParam)
- @MatrixParam (javax.ws.rs.MatrixParam)
- @FormParam (javax.ws.rs.FormParam)
- @HeaderParam (javax.ws.rs.HeaderParam)
- @Context (javax.ws.rs.core.Context)
- @Consumes (javax.ws.rs.Consumes)
- @Produces (javax.ws.rs.Produces)
- @Path specifies the relative URI path
- It can be defined at class-level or method-level
- Let understand by an example
Base URL for any web application is:
Append <url-pattern> tag from web.xml with Base URL that forms:
Append class-level @Path(“class-level”) annotation and then method-level @Path(“method-level”) annotation that forms:
Go through the examples in the upcoming articles to understand other annotations in detail
- Apache CXF: http://cxf.apache.org/docs/jax-rs.html
- JBoss RestEasy: http://docs.jboss.org/resteasy/docs/3.0.7.Final/userguide/html/
- Jersey: https://jersey.java.net/download.html
- Redhat: https://access.redhat.com/documentation/en-US/Red_Hat_JBoss_Fuse/6.0/html/Developing_RESTful_Web_Services/files/RESTIntro.html
- REST: http://rest.elkstein.org/
Opinions expressed by DZone contributors are their own.