Restful web services interview questions

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:

Was this post helpful?


You may also like:

Related Posts

  • Hibernate interview questions
    16 April

    Top 40+ Hibernate interview questions and answers

    Table of Contents1. What is ORM?2. What is Hibernate?3. What are advantages of Hibernate?4. Explain architecture of Hibernate?5. What are some core interfaces of hibernate?6. Explain brief about Session interface used in hibernate?7. Are session objects thread safe?8. Explain brief about SessionFactory object used in hibernate?9. What is Configuration class in hibernate?10. Explain brief about […]

  • Java Interview questions
    22 May

    100+ Core Java Interview Questions and Answers for 2022

    Table of ContentsIntroductionJava Interview QuestionsJava Interview TipsMore Java Interview Q&ACore java interview questionsCollections interview questionsMultithreading interview questionsJava 8 interview questionsOOPs interview questionsException Handling interview questionsString interview questionsSerialization interview questionsmethod overloading and method overriding interview questionsImmutable class interview questionsJava tricky interview questions Basic interview questions for fresher Interview questions for 5 to 7 years experiencedHow HashMap […]

  • Solid principles in java
    09 November

    SOLID Principles in Java

    Table of ContentsWhat is the meaning of S.O.L.I.D?Single Responsibility Principle (SRP)Open Closed Principle Liskov Substitution Principle Interface Segregation PrincipleDependency Inversion PrincipleWrap Up In this post, we will see 5 SOLID Principles in Java. Robert C. Martin gave five objected oriented design principles, and the acronym S.O.L.I.D is used for it. Each letter of this acronym […]

  • Java interview questions for 2 years experience
    08 November

    Java interview questions for 2 years experience

    Table of Contents1.   Can we override static method in java?2.   Can you overload main method in java?3. Can we override private methods in java?4. What is the base class for all the classes?5.   Can you list down some of important method from object class?6.   Which two methods should you override while putting the custom object as […]

  • Java interview questions for 5 years experience
    08 November

    Java interview questions for 5 years experience

    Table of Contents1. Guess the output of below program.2. Guess the output of below program.3. Guess the output of below program.4. What will happen in case of below program?5. What will happen in case of below program?6. What will happen in case of below program?7. Guess the output of below program.8. Guess the output of […]

  • Java tricky interview questions
    11 September

    Java technical interview questions

    Table of Contents1 How HashMap works in java?2 Which methods you should implement for key Object in HashMap?3. Guess the output of below program.4. Guess the output of below code.5. What are differences between Comparator and Comparable?6. What is difference between Error and Exception?7. What is ClassLoader in java?8. What are types of ClassLoader in java?9. […]

Leave a Reply

Your email address will not be published. Required fields are marked *

Subscribe to our newletter

Get quality tutorials to your inbox. Subscribe now.