JAX-RS and JAX-RS / REST implementations

What is JAX-RS and JAX-RS implementation, and what is different between these two.

rest

REST

REST (Representational State Transfer) is a architectural pattern with set of rules to be used for creating web services, and web services which follows these rules are called RESTful web services.

RESTful web services in Java

We can create RESTful web services in java by using JAX-RS, Spring or we can write our own servlets which expose required HTTP methods.

JAX-RS

JAX-RS is nothing but a specification or a contract in form of interfaces and annotations which can be used to create RESTful web services.

It comes with set of annotations which can be used to map a resource class as a web resource. Some of the annotations are @Path, @GET, @POST, @DELETE

JAX-RS implementations

So I just have to annotation my java class with these annotation and it will be expose as web service ?

No, JAX-RS is just specification that means you are just following the rules to expose your java class as web service but you need some JAX-RS implementation as well, which will have actual logic or implementation written to read java classes annotated with JAX-RS annotations and expose it as web service.

Like you cannot create list of objects just by using List you need some implementation of List like ArrayList or you cannot create a map of keys and values just by using Map you need its implementation like HashMap In the same way you cannot create RESTful web service just by using JAX-RS you need to have some JAX-RS implementations as well which has actual logic of representing your java classes as web services.

Below are some of the JAX-RS implementations

Conclusion

So JAX-RS is a specification which provides syntax and semantics of annotations which helps to expose RESTful web services and does not contain any logic to expose api, for the actual logic like decoding the request, parsing request details like performing marshaling and un-marshaling of received content, and executing java method mapped with annotation you need to select JAX-RS implementation.

This blog is open-source on Github.