Top 25 REST and RESTful APIs Interview Questions And Answers

his article is focused on to list down most frequently asked REST and RESTful APIs Interview Questions and Answers. This article will be helpful for freshers as well as an experienced software developer. 

It’s impossible to cover everything in a single article due to certain limitations, however, if you want to prepare for next technical interview then this article is the best starting point for you. So let’s begin to REST and RESTful APIs interview questions and answers.

REST and RESTful APIs Interview Questions And Answers


Frequently asked REST and RESTful APIs Interview Questions and Answers


Que 1. What is REST and RESTFUL?

Answer: REST stands for Representational State Transfer. It is a new way of writing web API.

Web services written by applying REST architectural concept are called RESTful services. These services focus on system resources and how state of resource should be transported over HTTP protocol to different clients written in different language. HTTP methods like GET, POST, PUT and DELETE can be used to perform CRUD operations in RESTFUL web service.

Que 2. What is REST?

Answer: REST stands for Representational State Transfer. It is a new way of writing web API. REST makes communication easy between remote computers by using the simple HTTP protocol which supports CRUD (Create, Read, Update, and Delete) operations on the server.

Que 3. What are the HTTP methods supported by REST?

Answer: The following are the HHTP methods supported by REST.

  • GET: Read-only access to a resource.
  • DELETE: Removes a resource.
  • OPTIONS: Indication on technique which are supported on a resource.
  • POST: Create a new resource.
  • PUT: Update an existing resource.

Que 4. Can we use GET request instead of POST to create a resource?

Answer: No, we are not supposed to use GET to create a resource. GET operations should contains view rights only.

Que 5. 5.What is the difference between PUT and POST?

Answer: PUT is used to update an existing resource, whereas POST is used to create a new resource.

Que 6. What are resources in a REST architecture?

Answer: Resources can be any information that can have a name. Resources are identified by logical URLs. It is a key element of a RESTful design. The domain entities of an application can be resources. (e.g. a person, a user, an invoice, a collection of invoices, etc.).

Que 7. How to represent a resource in REST?

Answer: REST uses different representations to represent a resource (e.g. text, JSON, XML). JSON and XML are the popular representations of resources.

Que 8. What are some key characteristics of REST?

Answer: Some key characteristics of REST:

  • REST is stateless hence the SERVER has no state (or session data)
  • The server could be restarted between two calls as every data is passed to the server with a well-designed REST API
  • REST uses HTTP methods for CRUD operation (e.g. REST uses GET to access resources), whereas web service mostly uses POST method to make operations.

Que 9. Which markup language can be used in restful Web API?

Answer: Following markup languages can be used in restful Web API

  1. JSON (JavaScript Object Notation)
  2. XML (Extensible Markup Language)

Que 10. Which protocol is used by RESTful webservices?

Answer: RESTful services use the HTTP protocol as a medium of communication between client and server.

Que 11. What is messaging in RESTful webservices?

Answer: A client sends an HTTP Request, and the server responds in the form of an HTTP Response. This mechanism is termed Messaging. Messaging contains message data and metadata i.e. information about the message itself.

Que 12. How JAXB related to RESTful web API?

Answer: JAXB stands for Java arch for XML binding.

Que 13. What is the purpose of HTTP Verb in REST based webservices?

Answer: HTTP Verbidentifies the operation to be performed on the resources.

Que 14. What are the core components of an HTTP Request and HTTP Response?

Answer: The following are the 5 major components of HTTP Request.

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

The following are the 4 major components of HTTP Response.

  1. Response (status) Code: Indicate Server status for the requested resource. (e.g. 404 – resource not found, and 200 – response is ok).
  2. HTTP Version: Indicate HTTP version
  3. Response Header: Contains metadata for the HTTP Response message as key-value pairs. (e.g. response date, server type, content length, content type, etc.)
  4. Response Body: Resource representation or Response message content

Que 15. What is statelessness in RESTful Web Service?

Answer: The communication between client and server must be stateless. The state is not maintained on the server is called as statelessness. It means that every HTTP request should complete in isolation. When a client makes an HTTP request, it includes all information necessary for the server to fulfill that request. The server never depends on the information from the previous requests.

Que 16. What are the advantages and disadvantages of statelessness in RESTful Webservices?

Answer:
Advantages:

  • Since HTTP itself is a stateless protocol so RESTful services work seamlessly with an HTTP protocol.
  • This simplifies your application design as the web service does not need to maintain the client’s previous interactions.
  • Services can be deployed on any number of servers because the server does not need to manage the session
  • It helps to improve visibility as web services can be treated each method request independently.

Disadvantages:

  • For every single request, you need to gather additional information and interpret it in case the client’s interactions need to be taken care of.

Que 17. What is the purpose of HTTP Status Code?

Answer: These HTTP Status codes are predefined standard codes and explain the status of tasks done at the server.

The following are the HTTP status code

  • 200: OK, success.
  • 201: CREATED, a resource is created successfully by using POST or PUT. It returns a link to a newly created resource using the location header.
  • 204: NO CONTENT, it indicates response body is empty
  • 304: NOT MODIFIED, it used to reduce network bandwidth usage in case of conditional GET requests
  • 400: BAD REQUEST, indicate invalid input is provided
  • 401: FORBIDDEN, indicates that the user is not having access to the method being used
  • 404: NOT FOUND, indicates that method is not available
  • 409: CONFLICT, indicates conflict situation while executing the method
  • 500: INTERNAL SERVER ERROR, indicates that the server has thrown some exception while executing the

Que 18. Which Webservices methods are read-only?

Answer: GET is read-only and are safe.

Que 19. What is idempotent operations?

Answer: Idempotent operations – result will always same regardless how many times these operations are invoked.

Que 20: Which Webservices methods are idempotent?

Answer: PUT and DELETE methods are idempotent.

Que 21. What is the use of the OPTIONS method of RESTful web services?

Answer: OPTIONS methods should list down all the supported operations in a web service, and it should be read-only.

Que 22. What is the use of a HEAD method of RESTful web services?

Answer: The HEAD method should return HTTP Header only, and it should be read-only.

Que 23. Which header of HTTP response sets the expiration date and time of caching?

Answer: Expires header used to set the expiration date and time of caching.

Que 24. What is the header of HTTP response provides control over caching?

Answer: Cache-Control is the primary header used to control caching.

Que 25. What are the best practices for caching in RESTful web services?

Answer: There are few best practices for caching based on the content type (static vs dynamic).

  • Static Content: Keep static contents (e.g. images, CSS, JavaScript) cacheable, with an expiration date of 2 – 3 days. Don’t keep the expiry date too high.
  • Dynamic Content: Dynamic content should be cached for several hours only.



Summary:

These are very basic REST and RESTFul APIs interview questions and answers that every developer or beginner should learn. I am sure this topic will be very helpful to everyone.