Follow @devglan

rest Interview Questions and Answers

Each rest Interview Question Sets contains 12 questions.

1)   What are webservices?

A web service is a collection of open protocols and standards used for exchanging data between applications or systems. Software applications written in various programming languages and running on various platforms can use web services to exchange data over computer networks like the Internet in a manner similar to inter-process communication on a single computer.

2)   What is REST?

REST stands for Representational State Transfer. It relies on a stateless, client-server, cacheable communications protocol -- and in virtually all cases, the HTTP protocol is used.
It is an architecture style for designing networked applications.It is a lightweight alternative to Web Services and RPC. REST design operations are self-contained, and each request carries with it (transfers) all the information (state) that the server needs in order to complete it.

3)   What are the HTTP methods used in REST for CRUD operation?

Following well known HTTP methods are commonly used in REST based architecture:
GET : Provides a read only access to a resource.
PUT : Used to create a new resource.
DELETE : Ued to remove a resource.
POST : Used to update a existing resource or create a new resource.
OPTIONS : Used to get the supported operations on a resource.

4)   What are the features of REST as a LightWeight Web Services?

Much like Web Services, a REST service is:
Platform-independent (you don't care if the server is Unix, the client is a Mac, or anything else),
Language-independent (C# can talk to Java, etc.),
Standards-based (runs on top of HTTP), and
Can easily be used in the presence of firewalls.
Like Web Services, REST offers no built-in security features, encryption, session management, QoS guarantees, etc. But also as with Web Services, these can be added by building on top of HTTP:

5)   What is a Resource in REST?

REST architecture treats every content as a resource. These resources can be text files, html pages, images, videos or dynamic business data. REST Server simply provides access to resources and REST client accesses and modifies the resources. Here each resource is identified by URIs/ global IDs.

6)   Which type of Webservices methods are to be idempotent?

PUT and DELETE operations are idempotent.

7)   How REST is simpler than SOAP. Give an example.

Using Web Services and SOAP, the request would look something like this:
<?xml version="1.0"?>
<soap:body pb="">
(The details are not important; this is just an example.) The entire shebang now has to be sent (using an HTTP POST request) to the server. The result is probably an XML file, but it will be embedded, as the "payload", inside a SOAP response envelope.
And with REST? The query will probably look like this:
Note that this isn't the request body -- it's just a URL. This URL is sent to the server using a simpler GET request, and the HTTP reply is the raw result data -- not embedded inside anything, just the data you need in a way you can directly use.

8)   What are the different responses of REST?

REST is not limited to any particular type of respnses. unlike SOAP services, REST is not bound to XML in any way. Possible formats include CSV (comma-separated values) and JSON (JavaScript Object Notation).

9)   What are the different status codes used in REST?

1. 1XX - information.
2. 2XX - Success
3. 3XX - Redirection
4.4XX - Client Error
5. 5XX - Server Error

10)   What is the use of Accept and Content-Type Headers in HTTP Request?

These are important headers in Restful web services. Accept headers tells web service what kind of response client is accepting, so if a web service is capable of sending response in XML and JSON format and client sends Accept header as “application/xml” then XML response will be sent. For Accept header “application/json”, server will send the JSON response.
Content-Type header is used to tell server what is the format of data being sent in the request. If Content-Type header is “application/xml” then server will try to parse it as XML data. This header is useful in HTTP Post and Put requests.

11)   Compare between REST and AJAX.

AJAX is a popular web development technique that makes web pages interactive using JavaScript.
In AJAX, requests are sent to the server using XMLHttpRequest objects. The response is used by the JavaScript code to dynamically change the current page.

12)   What difference between Jersey vs jax-rsin context to REST?

1. JAX-RS is an specification (just a definition) and Jersey is a JAX-RS implementation. For example: JAX-RS gives you a set of interfaces (standard Java interfaces) which are implemented by Jersey. So that set of interfaces (or classes) are needed as a dependency to be implemented.
2. In many ways, AJAX applications follow the REST design principles. Each XMLHttpRequest can be viewed as a REST service request, sent using GET. And the response is often in JSON, a popular response format for REST

Is this page helpful to you? Please give us your feedback below. We would love to hear your thoughts on these articles, it will help us improve further our learning process.