REST Web Service in Java Interview Questions | Page 2


Question 11:

When to use Query Parameter and when to use matrix parameter?

The parameters in a URI can either be query parameter or matrix parameters. There are many advantages of matrix parameter over query parameter: -

1) Matrix parameters are considered to be part of URI by proxies which allow it to be cached whereas URI's with "?" i.e query parameters are not cached.

2) Matrix parameters can be used at any point in the URI which makes it possible to set parameters where they are needed instead of appending all at the end.

3) Matrix parameters can occur with different sub-resources with different values in same URI 

 For example: - http://localhost/category;name=abc/article;name=xyz

Question 12:

Which of the HTTP methods are safe methods in REST Webservice?

GET, HEAD and OPTIONS are called as safe methods because issuing these requests does not change the state of the server(do not modify resources).

Safe methods are methods that can be cached, prefetched without any repercussions to the resource.

Question 13:

What are HTTP idempotent methods?

An idempotent HTTP method is a method that can be called many times without different outcomes. It does not matter if the method is called only once, or many times, the result is same.

Below are the list of idempotent methods:

OPTIONS

GET

HEAD

PUT

DELETE

Question 14:

How to delete resources using REST API ? Can we use GET/POST to delete resources, if not why?

We can use DELETE method of HTTP/HTTPS protocol to delete the resources using REST API. We cannot use POST/GET methods to delete the resources as it creates confusion ,because GET method is normally used to fetch data and POST method is normally used to submit the data and create new resources, and further if the url is mistakenly exposed as simple links to any bot/crawler it will simply delete the resources.

Question 15:

Describe some of the features of RESTful web service.

  • URI for resource identification :- Resources are determined by URIs exposed. Using this nURI and appropriate HTTP method client can directly access the resource.
  • CRUD operations :- REST-WS supports all CRUD operations i.e (create, read, update, delete)
  • Stateless :- As REST-WS is stateless every request to server must contain all information necessary to process the request.
  • Self Descriptive message :- Resources are decoupled from their representation so that the output can be generated in variety of formats like HTML, JSON, XML e.t.c

Question 16:

What is conditional GET method?

Using Conditional GET client asks a server if a resource has changed, if the resource state has changed then server responds back with resource else server replies with 304 Not Modified response, rather than the resource itself.
Any GET request is conditional if it uses "If-None-Match" header with the ETag set as the value or "If-Modified-Since". If the resource state changes subsequently ETag gets changed and the server responds with the resource.

Share interview questions

Comments

Comments
comments powered by Disqus

Navigation

Social Media