Restful web services interview questions

Restful web services are very popular now a days because it is very simple to implement and less time consuming. In this post, we are going to see restful web services interview questions with answers.

1. What is REST?

REST is an architectural style which was brought in by Roy Fielding in 2000 in his doctoral thesis.

In the REST architecture style, clients and servers exchange representations of resources by using a standardized interface and protocol.REST isn't protocol specific, but when people talk about REST they usually mean REST over HTTP.

2. What are Restful web services?

In the web services terms, REpresentational State Transfer (REST) is a stateless client-server architecture in which the web services are viewed as resources and can be identified by their URIs. Web services client uses that URI to access the resource.
It consists of two components REST server which provides access to the resources and a REST client which accesses and modify the REST resources.

3. What are important features of Restful web services?

Some important features of Restful web services are:
Resource identification through URI:Resources are identified by their URIs (typically links on internet). So, a client can directly access a RESTful Web Services using the URIs of the resources (same as you put a website address in the browser’s address bar and get some representation as response).
Uniform interface: Resources are manipulated using a fixed set of four create, read, update, delete operations: PUT, GET, POST, and DELETE.
Client-Server: A clear separation concerns is the reason behind this constraint. Separating concerns between the Client and Server helps improve portability in the Client and Scalability of the server components.
Stateless: each request from client to server must contain all the information necessary to understand the request, and cannot take advantage of any stored context on the server.
Cache: to improve network efficiency responses must be capable of being labeled as cacheable or non-cacheable.
Named resources - the system is comprised of resources which are named using a URL.
Interconnected resource representations - the representations of the resources are interconnected using URLs, thereby enabling a client to progress from one state to another.
Layered components - intermediaries, such as proxy servers, cache servers, gateways, etc, can be inserted between clients and resources to support performance, security, etc.
Self-descriptive messages: Resources are decoupled from their representation so that their content can be accessed in a variety of formats, such as HTML, XML, plain text, PDF, JPEG, JSON, and others.

4. What are HTTP methods that can be used in Restful web services?

RESTful web services use HTTP protocol methods for the operations they perform.
Some important Methods are:
GET : It defines a reading access of the resource without side-effects.This operation is idempotent i.e.they can be applied multiple times without changing the result
PUT : It is generally used for updating resource. It must also be idempotent.
DELETE : It removes the resources. The operations are idempotent i.e. they can get repeated without leading to different results.
POST : It is used for creating a new resource. It is not idempotent.

5. What do you mean by Idempotent and which HTTP methods are idempotent?

Idempotent means result of multiple successful request will not change state of resource after initial application
For example : Delete is idempotent method because when you first time use delete, it will delete the resource (initial application) but after that, all other request will have no result because resource is already deleted. Get, put and delete are HTTP Idempotent methods.

6. What are differences between Post and Put Http methods?

POST :It is used for creating a new resource. It is not idempotent.
PUT : It is generally used for updating resource. It is idempotent.
Idempotent means result of multiple successful request will not change state of resource after initial application

7. What happens if resources are shared by multiple clients? Do you need to make it thread safe explicitly?

New resource instance is created for each request, so you don't need to implement thread safety or synchronization aid. It is by default thread safe.

8. What is JAX-RS?

Java API for RESTful Web Services (JAX-RS), is a set if APIs to developer REST service. JAX-RS is part of the Java EE6, and make developers to develop REST web application easily.

9. What are REST frameworks that you are aware of and which can be used to create Restful webservices?

There are multiple Rest framework that can be used to create Restful web services such as
  • Jersey
  • RestEasy
  • Restlet
  • CFX
  • Spring Rest webservices

10. What are some important annotations which you use to create Restful web services?

Some of important annotations which are used for creating web services are:
@Path : This is used to set path for URI at class level or method level
@GET,@POST,@PUT,@DELETE  : There are annotations corresponds to HTTP methods
@Produces(MediaType.TEXT_XML [, more-types ]): @Produces defines which MIME type is delivered by a method
@PathParam: Used to inject values from the URL into a method parameter.
@Consumes(MediaType.TEXT_XML) : @Cosumes defines which MIME type will be consumed by the method .

11. Can you use get method to create Resources rather than post?

No, Get should be used only for resource retrieval and not for resource creation.

12.  What are ways to test Restful web services?

You require a restful client to test restful web services. You can use:
  • Postman for chrome browser
  • poster for firefox
You may also like:
    Web services interview questions Core java interview questions Spring interview questions Hibernate interview questions Java Collections interview questions Java String interview questions
Please share more questions on restful web services and I will add it to the list.

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus


Java tutorial for beginners Copyright © 2012