Restful Web Services Interview Questions and Answers
by Mohammed, on Apr 6, 2018 11:45:58 AM
Q1. What are RESTful webservices?
Ans: 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.
Q2. What is differences between RESTful web services and SOAP web services ?
Ans: Though both RESTful Web Services and SOAP web service can operate cross platform they are architecturally different to each other, here is some of differences between REST and SOAP:
1. REST is more simple and easy to use than SOAP
2. REST uses HTTP protocol for producing or consuming web services while SOAP uses XML.
3. REST is lightweight as compared to SOAP and preferred choice in mobile devices and PDA's.
4. REST supports different format like text, JSON and XML while SOAP only support XML.
5. REST web services call can be cached to improve performance.
Q3. What is Resource in REST framework ?
Ans: it represent a "resource" in REST architecture. on RESTLET API it has life cycle methods like init(), handle() and release() and contains a Context, Request and Response corresponding to specific target resource. This is now deprecated over ServerResource class and you should use that. see Restlet documentation for more details.
Q4. What are important features of Restful web services?
Ans: 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
Q5. What are HTTP methods that can be used in Restful web services?
Ans: 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.
Q6. What are the tools used for creating RESTFull web services ?
Q7. What do you mean by Idempotent and which HTTP methods are idempotent?
Ans: 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.
Q8. 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
Q9. What is statelessness in RESTful Webservices?
Ans: 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.
Q10. What are the advantages of statelessness in RESTful Webservices?
Ans: Following are the benefits of statelessness in RESTful web services
Web services can treat each method request independently. Web services need not to maintain client's previous interactions. It simplifies application design. As HTTP is itself a statelessness protocol, RESTful Web services work seamlessly with HTTP protocol.
Q11. What are the disadvantages of statelessness in RESTful Webservices?
Ans: Following is the disadvantage of statelessness in RESTful web services ? 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.
Q12. What are the best practices for caching?
Q13. How to display custom error pages using RestFull web services ?
Ans: In order to customize error you need to extend StatusService and implement getRepresentation(Status, Request, Response) method with your custom code now assign instance of your CustomStatusService to appropriate "statusService property".
Q14. What happens if RestFull resources are accessed by multiple clients ? do you need to make it thread-safe?
Ans: Since a new Resource instance is created for every incoming Request there is no need to make it thread-safe or add synchronization. multiple client can safely access RestFull resources concurrently.
That’s all on REST interview questions , I will add couple of more REST Interview questions whenever I got them from my friend circle.
Q15. What is JAX-RS?
Ans: 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.
Q16. What are REST frameworks that you are aware of and which can be used to create Restful webservices?
Ans: There are multiple Rest framework that can be used to create Restful web services such as
- Spring Rest webservices
Q17. What is addressing in RESTful webservices?
Ans: Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.
Q18. What are important constraints for a RESTful Web Service?
Ans: The five important constraints for RESTful Web Service are
- Client - Server : There should be a service producer and a service consumer.
- The interface (URL) is uniform and exposing resources. Interface uses nouns (not actions)
- The service is stateless. Even if the service is called 10 times, the result must be the same.
- The service result should be Cacheable. HTTP cache, for example.
- Service should assume a Layered architecture. Client should not assume direct connection to server - it might be getting info from a middle layer - cache.
Q19. What should be the purpose of HEAD method of RESTful web services?
Ans: It should return only HTTP Header, no Body and should be read only.
Q20. Which type of Webservices methods are to be read only?
Ans: GET operations are read only and are safe.
Related Interview Questions...