Restful web service Interview Questions & Answers

  1. Question 1. What Rest Stands For?

    Answer :

    REST stands for REpresentational State Transfer.

  2. Question 2. What Is Rest?

    Answer :

    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.

  3. Web Service Testing Interview Questions

  4. Question 3. Name Some Of The Commonly Used Http Methods Used In Rest Based Architecture?

    Answer :

    Following well known HTTP methods are commonly used in REST based architecture:−

    • GET − Provides a read only access to a resource.
    • PUT − Used to create a new resource.
    • DELETE − Ued to remove a resource.
    • POST − Used to update a existing resource or create a new resource.
    • OPTIONS − Used to get the supported operations on a resource.
  5. Question 4. What Are Web Services?

    Answer :

    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.

  6. Web Service Testing Tutorial

  7. Question 5. What Are Restful Web Services?

    Answer :

    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.

  8. Web Services Interview Questions

  9. Question 6. What Is A Resource In Rest?

    Answer :

    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.

  10. Question 7. How To Represent A Resource In Rest?

    Answer :

    REST uses various representations to represent a resource where text, JSON, XML. XML and JSON are the most popular representations of resources.

  11. Web Services Tutorial
    Core Java Interview Questions

  12. Question 8. What Are The Best Practices To Design A Resource Representation?

    Answer :

    Following are important points to be considered while designing a representation format of a resource in a RESTful web services:

    • 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.
  13. Question 9. Which Protocol Is Used By Restful Web Services?

    Answer :

    RESTful web services make use of HTTP protocol as a medium of communication between client and server.

  14. Java-Springs Interview Questions

  15. Question 10. What Is Messaging In Restful Web Services?

    Answer :

    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.

  16. Core Java Tutorial

  17. Question 11. What Are The Core Components Of A Http Request?

    Answer :

    A HTTP Request has five major parts :

    1. Verb − Indicate HTTP methods such as GET, POST, DELETE, PUT etc.
    2. URI − Uniform Resource Identifier (URI) to identify the resource on server.
    3. HTTP Version − Indicate HTTP version, for example HTTP v1.1 .
    4. Request Header − Contains metadata for the HTTP Request message as key-value pairs. For example, client ( or browser) type, format supported by client, format of message body, cache settings etc.
    5. Request Body − Message content or Resource representation.
  18. CSS Interview Questions

  19. Question 12. What Are The Core Components Of A Http Response?

    Answer :

    A HTTP Response has four major parts:-

    1. Status/Response Code − Indicate Server status for the requested resource. For example 404 means resource not found and 200 means response is ok.
    2. HTTP Version − Indicate HTTP version, for example HTTP v1.1 .
    3. Response Header − Contains metadata for the HTTP Response message as key-value pairs. For example, content length, content type, response date, server type etc.
    4. Response Body − Response message content or Resource representation.
  20. Web Service Testing Interview Questions

  21. Question 13. What Is Addressing In Restful Web Services?

    Answer :

    Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.

  22. Java-Springs Tutorial

  23. Question 14. What Is Uri?

    Answer :

    URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its URI.

  24. Question 15. What Is Purpose Of A Uri In Rest Based Web Services?

    Answer :

    Purpose of an URI is to locate a resource(s) on the server hosting the web service.

  25. Java Abstraction Interview Questions

  26. Question 16. What Is Format Of A Uri In Rest Architecture?

    Answer :

    A URI is of following format:−

    :////

  27. CSS Tutorial

  28. Question 17. What Is The Purpose Of Http Verb In Rest Based Web Services?

    Answer :

    VERB identifies the operation to be performed on the resource.

  29. Amazon Web Services (AWS) Interview Questions

  30. Question 18. What Are The Best Practices To Create A Standard Uri For A Web Service?

    Answer :

    Following are important points to be considered while designing a URI

    • Use Plural Noun − Use plural noun to define resources. For example, we’ve used users to identify users as a resource.
    • 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.
  31. Web Services Interview Questions

  32. Question 19. What Is Statelessness In Restful Web Services?

    Answer :

    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.

  33. Restful web service Tutorial

  34. Question 20. What Are The Advantages Of Statelessness In Restful Web Services?

    Answer :

    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.
  35. RESTful JAVA Web Services Interview Questions

  36. Question 21. What Are The Disadvantages Of Statelessness In Restful Web Services?

    Answer :

    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.

  37. Question 22. What Do You Mean By Idempotent Operation?

    Answer :

    Idempotent operations means their result will always same no matter how many times these operations are invoked.

  38. Spring MVC Framework Tutorial

  39. Question 23. Which Type Of Web Services Methods Are To Be Idempotent?

    Answer :

    PUT and DELETE operations are idempotent.

  40. Spring MVC Framework Interview Questions

  41. Question 24. Which Type Of Web Services Methods Are To Be Read Only?

    Answer :

    GET operations are read only and are safe.

  42. Core Java Interview Questions

  43. Question 25. What Is The Difference Between Put And Post Operations?

    Answer :

    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.

  44. Question 26. What Should Be The Purpose Of Options Method Of Restful Web Services?

    Answer :

    It should list down the supported operations in a web service and should be read only.

  45. Soap Web Services Interview Questions

  46. Question 27. What Should Be The Purpose Of Head Method Of Restful Web Services?

    Answer :

    It should return only HTTP Header, no Body and should be read only.

  47. Java-Springs Interview Questions

  48. Question 28. What Is Caching?

    Answer :

    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.

  49. Question 29. Which Header Of Http Response, Provides The Date And Time Of The Resource When It Was Created?

    Answer :

    Date header provides the date and time of the resource when it was created.

  50. Question 30. Which Header Of Http Response, Provides The Date And Time Of The Resource When It Was Last Modified?

    Answer :

    Last Modified header provides the date and time of the resource when it was last modified.

  51. Question 31. Which Header Of Http Response Provides Control Over Caching?

    Answer :

    Cache-Control is the primary header to control caching.

  52. Question 32. Which Header Of Http Response Sets Expiration Date And Time Of Caching?

    Answer :

    Expires header sets expiration date and time of caching.

  53. Question 33. Which Directive Of Cache Control Header Of Http Response Indicates That Resource Is Cacheable By Any Component?

    Answer :

    Public directive indicates that resource is cacheable by any component.

  54. CSS Interview Questions

  55. Question 34. Which Directive Of Cache Control Header Of Http Response Indicates That Resource Is Catchable By Only Client And Server, No Intermediary Can Cache The Resource?

    Answer :

    Private directive indicates that resource is cachable by only client and server, no intermediary can cache the resource.

  56. Question 35. Which Directive Of Cache Control Header Of Http Response Indicates That Resource Is Not Cacheable?

    Answer :

    no-cache/no-store directive indicates that resource is not cacheable.

  57. Question 36. Which Directive Of Cache Control Header Of Http Response Can Set The Time Limit Of Caching?

    Answer :

    max-age directive indicates that the caching is valid up to max-age in seconds. After this, client has to make another request.

  58. Java Abstraction Interview Questions

  59. Question 37. Which Directive Of Cache Control Header Of Http Response Provides Indication To Server To Revalidate Resource If Max-age Has Passed?

    Answer :

    must-revalidate directive provides indication to server to revalidate resource if max-age has passed.

  60. Question 38. What Are The Best Practices For Caching?

    Answer :

    Always keep static contents like images, css, JavaScript cacheable, with expiration date of 2 to 3 days. Never keep expiry date too high.
    Dynamic contents should be cached for few hours only.

  61. Question 39. What Are The Best Practices To Be Followed While Designing A Secure Restful Web Service?

    Answer :

    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.
  62. Question 40. What Is The Purpose Of Http Status Code?

    Answer :

    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.

  63. Amazon Web Services (AWS) Interview Questions

  64. Question 41. What Http Status Code 200 States?

    Answer :

    It means, OK, shows success.

  65. Question 42. What Http Status Code 201 States?

    Answer :

    It means, CREATED, when a resource is successful created using POST or PUT request. Return link to newly created resource using location header.

  66. RESTful JAVA Web Services Interview Questions

  67. Question 43. What Http Status Code 204 States?

    Answer :

    It means, NO CONTENT, when response body is empty for example, a DELETE request.

  68. Question 44. What Http Status Code 304 States?

    Answer :

    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.

  69. Question 45. What Http Status Code 400 States?

    Answer :

    It means, BAD REQUEST, states that invalid input is provided e.g. validation error, missing data.

  70. Question 46. What Http Status Code 401 States?

    Answer :

    It means, FORBIDDEN, states that user is not having access to method being used for example, delete access without admin rights.

  71. Question 47. What Http Status Code 404 States?

    Answer :

    It means, NOT FOUND, states that method is not available.

  72. Question 48. What Http Status Code 409 States?

    Answer :

    It means, CONFLICT, states conflict situation while executing the method for example, adding duplicate entry.

  73. Question 49. What Http Status Code 500 States?

    Answer :

    It means, INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method.

  74. Question 50. What Is Jax-rs?

    Answer :

    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 to simplify development of JAVA based web services creation and deployment. It also provides supports for creating clients for RESTful web services.