Restful Web Services Question and Answers
Restful Web Services Question and Answers
RESTful web service implementation defines the method of accessing various resources which are required by the
client and he has sent the request to the server through the web browser. The important aspects of this
implementation include:
Resources
Request Headers
Request Body
Response Body
Status codes
Q #2) Name the protocol which is used by RESTful web services.
RESTful web services use a famous web protocol i.e. HTTP protocol. This serves as a medium of data
communication between client and server. HTTP standard methods are used to access resources in RESTful web
service architecture.
Q #3) Explain the term ‘Addressing’ with respect to RESTful WEB service.
Just like we require address with postal code to reach any person, in the same way, ‘Addressing’ locates resources
that are present on the server for the purpose of hosting web services. This is usually done with URI i.e. Unified
Resource Identifier.
Messages are the collection of information about the data i.e. Metadata.
Q #6) What are the core components of HTTP request and HTTP response?
The core components that come under HTTP Request are:
Every client passes a ‘session identifier’ which also acts as an identifier for each session.
Advantages:
Every method required for communication is identified as an independent method i.e. there are no
dependencies to other methods.
Any previous communication with the client and server is not maintained and thus the whole process is
very much simplified.
If any information or metadata used earlier in required in another method, then the client sends again
that information with HTTP request.
HTTP protocol and REST web service, both shares the feature of statelessness.
Disadvantages:
In every HTTP request from the client, the availability of some information regarding the client state is
required by the web service.
Q #9) Enlist some important constraints for RESTful web services.
Every constraint has positive as well as negative impacts and to produce an overall architecture, there should be
the balance between both of them. Below mentioned are some important constraints for RESTful web service:
There should be separate concerns for each server and client which will help to maintain the modularity
within the application. This will also reduce the complexity and increase the scalability.
The client-server communication should be stateless, which means no previous information is used and
the complete execution is done in isolation. In cases of failure, it also helps the client to recover.
In client-server communication, the HTTP response should be cacheable so that when required cached
copy can be used which in turn enhances the scalability and performance of the server.
The fourth constraint is the uniform interface which allows client-server interaction to be easily
understood. This constraint is further divided into four sub-constraints as:
Resource Identification
Resource manipulation
Each message is easily understood and is self-descriptive.
Hypermedia, which is defined as the text with hyperlinks and when clicked it moves to another
application state.
Client-server communication should be done on a layered system and thus the client should only have
knowledge about the intermediate level with which communication is being done,
Q #10) What is a ‘Resource’?
Just like the ‘Object’ instance, we have learned in object orient programming Language, in the same way,
‘Resource’ is defined as an object of a type which can be an image, HTML file, text data, and any type of dynamic
data. There are varieties of representation formats available in order to represent a resource.
Q #12) Enlist some important points that should be kept in mind while designing Resources representation for
RESTful web services.
As there are no restrictions on the format in which the resource representation is done but just that the main
requirement is the format of the representation should be as per the client requirement. A good resource
representation is designed by considering the following main points:
The resource representation format should be easily understood by the client and server.
The representation should be complete regardless of its format structure, which may be complex or
simple.
In the case of the link of the resources to other resources, such cases should also be considered and
handled.
Q #13) What is Caching?
Caching is the process in which server response is stored so that a cached copy can be used when required and
there is no need of generating the same response again. This process not only reduces the server load but in turn
increase the scalability and performance of the server. Only the client is able to cache the response and that too
for a limited period of time.
Mentioned below are the header of the resources and their brief description so that they can be identified for the
caching process:
Public: Resources that are marked as the public can be cached by any intermediate components between
the client and server.
Private: Resources that are marked as private can only be cached by the client.
No cache means that particular resource cannot be cached and thus the whole process is stopped.
Q #15) What are the best practices that are to be followed while designing RESTful web services?
To design a secure RESTful web service, there are some best practices or say points that should be considered.
These are explained as follows:
There is no limit of sending data as payload through POST method but the only concern is that more data with
consuming more time and bandwidth. This may consume much of user’s time also.
GET: This is a read only operation which fetches the list of users on the server.
PUT: This operation is used for the creation of any new resource on the server.
POST: This operation is used for updating an old resource or for creating a new resource.
DELETE: As the name suggests, this operation is used for deleting any resource on the server.
OPTIONS: This operation fetches the list of any supported options of resources that are available on the
server.
Q #18) What is the difference between PUT method and POST method?
The major difference between the PUT and POST method is that the result generated with PUT method is always
same no matter how many times the operation is performed. On the other hand, the result generated by POST
operation is always different every time.
Q #20) What are HTTP status codes? Enlist few with meaning.
HTTP status codes basically are the representation of the status of the task that has been performed on the server,
with the mode of some codes. Every code has their own meaning.
Some of the HTTP status codes with their meaning are as follows:
Code 200: This indicates success.
Code 201: This indicates resource has been successfully created.
Code 204: This indicates that there is no content in the response body.
Code 404: This indicates that there is no method available.
There are few more such codes that indicate the status.
Conclusion:
This article will help you prepare for the RESTful web services interview and help you to understand the concept in
the simple and easy way. I have tried to cover all the areas which are very necessary for having the complete
knowledge about RESTful Web services.
Just remember, it may be possible that you are not able to answer all questions in the interview but whatever you
answer should be accurate. Your basic concept should be strong and your confidence level should be high.