RESTful Web Services - Interview Questions - Tutorialspoint
RESTful Web Services - Interview Questions - Tutorialspoint
Dear readers, these RESTful Web services Interview Questions have been designed specially to
get you acquainted with the nature of questions you may encounter during your interview for the
subject of RESTful Web services. As per my experience good interviewers hardly plan to ask any
particular question during your interview, normally questions start with some basic concept of the
subject and later they continue based on further discussion and what you answer −
What is REST?
REST is web standards based architecture and uses HTTP Protocol for data communication. It
revolves around resource where every component is a resource and a resource is accessed by a
common interface using HTTP standard methods. REST was first introduced by Roy Fielding in
2000.
In REST architecture, a REST Server simply provides access to resources and REST client
accesses and presents the resources. Here each resource is identified by URIs/ global IDs. REST
uses various representations to represent a resource like text, JSON and XML. Now a days JSON
is the most popular format being used in web services.
Name some of the commonly used HTTP methods used in REST based
architecture?
Following well-known HTTP methods are commonly used in REST based architecture −
GET − Provides read-only access to a resource.
PUT − Used to update an existing resource or create a new resource.
DELETE − Used to remove a resource.
POST − Used to create a new resource.
OPTIONS − Used to get the supported operations on a resource.
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 1/9
2/24/2021 RESTful Web services - Interview Questions - Tutorialspoint
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.
Web services based on REST Architecture are known as RESTful web services. These web
services use HTTP methods to implement the concept of REST architecture. A RESTful web
service usually defines a URI, Uniform Resource Identifier a service, provides resource
representation such as JSON and set of HTTP Methods.
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.
REST uses various representations to represent a resource where text, JSON, XML. XML and
JSON are the most popular representations of resources.
Understandability − Both Server and Client should be able to understand and utilize the
representation format of the resource.
Completeness − Format should be able to represent a resource completely. For example,
a resource can contain another resource. Format should be able to represent simple as
well as complex structures of resources.
Linkablity − A resource can have a linkage to another resource, a format should be able
to handles such situations.
RESTful web services make use of HTTP protocol as a medium of communication between client
and server.
A client sends a message in form of a HTTP Request and server responds in form of a HTTP
Response. This technique is termed as Messaging. These messages contain message data and
metadata i.e. information about message itself.
Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to
locate a postal address of a person.
What is URI?
URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its
URI.
Purpose of an URI is to locate a resource(s) on the server hosting the web service.
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 3/9
2/24/2021 RESTful Web services - Interview Questions - Tutorialspoint
<protocol>://<service-name>/<ResourceType>/<ResourceID>
What are the best practices to create a standard URI for a web service?
Avoid using spaces − Use underscore(_) or hyphen(-) when using a long resource name,
for example, use authorized_users instead of authorized%20users.
Use lowercase letters − Although URI is case-insensitive, it is good practice to keep url in
lower case letters only.
Maintain Backward Compatibility − As Web Service is a public service, a URI once
made public should always be available. In case, URI gets updated, redirect the older URI
to new URI using HTTP Status code, 300.
Use HTTP Verb − Always use HTTP Verb like GET, PUT, and DELETE to do the
operations on the resource. It is not good to use operations names in URI.
As per REST architecture, a RESTful web service should not keep a client state on server. This
restriction is called statelessness. It is responsibility of the client to pass its context to server and
then server can store this context to process client's further request. For example, session
maintained by server is identified by session identifier passed by the client.
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 4/9
2/24/2021 RESTful Web services - Interview Questions - Tutorialspoint
As HTTP is itself a statelessness protocol, RESTful Web services work seamlessly with
HTTP protocol.
Web services need to get extra information in each request and then interpret to get the client's
state in case client interactions are to be taken care of.
Idempotent operations means their result will always same no matter how many times these
operations are invoked.
PUT and POST operation are nearly same with the difference lying only in the result where PUT
operation is idempotent and POST operation can cause different result.
It should list down the supported operations in a web service and should be read only.
It should return only HTTP Header, no Body and should be read only.
What is caching?
Caching refers to storing server response in client itself so that a client needs not to make server
request for same resource again and again. A server response should have information about how
a caching is to be done so that a client caches response for a period of time or never caches the
server response.
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 5/9
2/24/2021 RESTful Web services - Interview Questions - Tutorialspoint
Which header of HTTP response, provides the date and time of the resource
when it was created?
Date header provides the date and time of the resource when it was created.
Which header of HTTP response, provides the date and time of the resource
when it was last modified?
Last Modified header provides the date and time of the resource when it was last modified.
Which header of HTTP response sets expiration date and time of caching?
Private directive indicates that resource is cachable by only client and server, no intermediary can
cache the resource.
Which directive of Cache Control Header of HTTP response can set the time
limit of caching?
max-age directive indicates that the caching is valid up to max-age in seconds. After this, client has
to make another request.
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 6/9
2/24/2021 RESTful Web services - Interview Questions - Tutorialspoint
Always keep static contents like images, css, JavaScript cacheable, with expiration date of 2 to 3
days. Never keep expiry date too high.
What are the best practices to be followed while designing a secure RESTful
web service?
As RESTful web services work with HTTP URLs Paths so it is very important to safeguard a
RESTful web service in the same manner as a website is be secured. Following are the best
practices to be followed while designing a RESTful web service −
Validation − Validate all inputs on the server. Protect your server against SQL or NoSQL
injection attacks.
Session based authentication − Use session based authentication to authenticate a user
whenever a request is made to a Web Service method.
No sensitive data in URL − Never use username, password or session token in URL ,
these values should be passed to Web Service via POST method.
Restriction on Method execution − Allow restricted use of methods like GET, POST,
DELETE. GET method should not be able to delete data.
Validate Malformed XML/JSON − Check for well formed input passed to a web service
method.
Throw generic Error Messages − A web service method should use HTTP error
messages like 403 to show access forbidden etc.
HTTP Status code are standard codes and refers to predefined status of task done at server. For
example, HTTP Status 404 states that requested resource is not present on server.
It means, CREATED, when a resource is successful created using POST or PUT request. Return
link to newly created resource using location header.
It means, NO CONTENT, when response body is empty for example, a DELETE request.
It means, NOT MODIFIED, used to reduce network bandwidth usage in case of conditional GET
requests. Response body should be empty. Headers should have date, location etc.
It means, BAD REQUEST, states that invalid input is provided e.g. validation error, missing data.
It means, FORBIDDEN, states that user is not having access to method being used for example,
delete access without admin rights.
It means, CONFLICT, states conflict situation while executing the method for example, adding
duplicate entry.
It means, INTERNAL SERVER ERROR, states that server has thrown some exception while
executing the method.
What is JAX-RS?
JAX-RS stands for JAVA API for RESTful Web Services. JAX-RS is a JAVA based programming
language API and specification to provide support for created RESTful Webservices. Its 2.0 version
was released in 24 May 2013. JAX-RS makes heavy use of annotations available from Java SE 5
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 8/9
2/24/2021 RESTful Web services - Interview Questions - Tutorialspoint
to simplify development of JAVA based web services creation and deployment. It also provides
supports for creating clients for RESTful web services.
What is Next ?
Further you can go through your past assignments you have done with the subject and make sure
you are able to speak confidently on them. If you are fresher then interviewer does not expect you
will answer very complex questions, rather you have to make your basics concepts very strong.
Second it really doesn't matter much if you could not answer few questions but it matters that
whatever you answered, you must have answered with confidence. So just feel confident during
your interview. We at tutorialspoint wish you best luck to have a good interviewer and all the very
best for your future endeavor. Cheers :-)
https://www.tutorialspoint.com/restful/restful_interview_questions.htm 9/9