We interact and communicate with people using body gestures, facial expressions, and different languages. Thus, we can express and share our ideas easily with others. But what about the communication among various software programs installed on computers and smart devices? They do not use any facial expressions or body gestures to interact with us or with one another.
As a user interface helps us to communicate with computers and applications, an application program interface (API) helps computers and software applications to communicate with each other. This article will assist you in understanding what an API is and some commonly-asked REST API interview questions. So, let us begin with a quick introduction to API.
What is Application Program Interface (API)?
For devices and their components to communicate with each other, there is a special and unique machine-readable interface called Application Program Interface or API. An Application Program Interface (API) acts as a software mediator between two different applications and promotes communication between them.
To get a clear idea about what an API is, let us take one generic example. Imagine that you are at a restaurant having a menu card on your table, and a waiter is ready to take your order. The kitchen in the restaurant acts as a system, where the ordered food gets prepared. The waiter notes down your order and conveys the ordered food items to the kitchen, and gets back to you with your ordered food. Therefore, a communication medium between you and the kitchen is a waiter.
The same is the process when two different software programs connect. Their communication medium is an Application Program Interface (API).
There are different types of APIs available. Also, there are specific standards and protocols that developers use for creating new APIs. We will discuss both of them in the upcoming sections.
Types of APIs
Four distinct types of APIs are explained below:
1. Open APIs
As its name suggests, Open APIs are available for outside businesses or developers with the least restrictions. Hence, it is also named a Public API.
2. Internal APIs
When an API is intended to be utilized within an organization or enterprise, it is called an Internal API.
3. Composite APIs
As its name indicates, a Composite API is a collection of two or more APIs used for creating a sequence of interdependent or dependent operations.
4. Partner APIs
An API allowed to be accessed by only the specified and authorized people is called a Partner API.
Protocols and Architecture in API
API utilizes specific standards and protocols for data exchange. These protocols and standards are specific rules and constraints that help API operations to run smoothly. Three typically used API protocols and standards are given below:
W3C has defined SOAP or Simple Object Access Protocol as a messaging protocol used for developing web APIs. In addition, the SOAP protocol states the requirement to create a SOAP message, its features, and the communication protocol it uses. It supports the XML message format.
RPC or Remover Procedure Call is one of the simplest API protocols. There are two distinct kinds of RPC’s – JSON and XML. The JSON-RPC encodes its calls using the JSON language. On the other hand, XML-RPC uses the XML language to encode its calls.
The above two were web service API protocols. However, REST is not a protocol; instead, it is a set of multiple architectural principles. The full form for REST is Representational State Transfer and it is an API architecture.
30 Best REST API Interview Questions and Answers
If you are preparing for a REST API developer job interview, you might be looking for the frequently asked RESTful web services interview questions. And if that’s exactly what you want, you have landed at the right place. This section consists of commonly asked REST API interview questions and answers that you need to know.
We divided the entire set of REST API interview questions into three levels, namely Beginners, Intermediate, and Advanced. Let us begin with beginner-level.
Beginner-Level REST API Interview Questions
1. Explain REST and RESTful.
REST stands for REpresentational State Transfer, and it is a combination of various architectural principles used for creating web APIs. In other words, REST is a set of rules that addresses how an internet-based system, like the web, should behave.
RESTful is a web service that follows all architectural principles and standards established by REST. The primary objective of RESTful web services is to concentrate on system resources. In addition, these web services focus on transmitting the resource’s state to various clients in different languages over the HTTP protocol.
Client-Server applications use the REST architecture style. Such applications concentrate on transmitting resources’ representation using requests and responses. Here, resources are the data and functionality of the system. Furthermore, REST APIs use Uniform Resource Identifiers (URIs) to access resources.
2. Define a REST Resource.
A REST Resource is any content, like data or functionality, present in the REST architecture. In addition, the resource in the REST architecture is similar to objects used in object-oriented programming. For example, resources in the REST architecture can be HTML pages, text files, documents, images, etc.
Furthermore, we can identify a resource uniquely using its respective Uniform Resource Identifier (URI). For example, some generic resources are XML, JSON, HTML, and YAML.
3. Explain the term URI.
URI in the REST architecture is an acronym for Uniform Resource Identifier. Every resource is assigned a unique and distinctive Uniform Resource Identifier. Thus, a URI identifies a unique resource present in the REST design. The format of URI is shown below:
In the REST protocol, there are two different kinds of URI:
Its full form is Uniform Resource Locator. As its name suggests, a URL contains information about retrieving a resource from its location. Moreover, A URI consists of a protocol, such as FTP, http, etc., a network hostname, and a path to the specific document.
For instance, consider we use the http protocol. Let us take the network hostname as techgeekbuzz.com and the path of the required document as samplePage.html.
The URL will be:
URN is an acronym for Uniform Resource Name. By using URN, we can identify a resource with its name. However, resources’ names are unique and persistent. Therefore, there is nothing to do with the resource location while writing a URN for any resource
For example, consider that you wish to find a book having an ISBN as 1231234567. Then, its URN will be as follows:
|urn: isbn: 1231234567|
4. Explain the features of RESTful Web Services.
The key characteristics of RESTful Web Services are:
- These web services follow the client-server model, which means that a client should be able to access the server that consists of resources and conditions.
- RESTful web services utilize one of the most used communication protocols called the HTTP protocol to retrieve resources, execute queries, or perform any other operation.
- The interchange of data between the REST client and the REST server in the RESTful web service is called ‘Messaging.’
- RESTful web services follow the idea of statelessness, i.e., the request and the response from the client are independent. Therefore, RESTful web services assure that the client gets the requested data and sends the desired responses.
- All the information received by the server is cache-enabled. Hence, it helps to enhance the productivity of the network traffic.
5. Explain the term ‘statelessness’ in the REST protocol
The term ‘statelessness’ in the REST architecture implies that the server does not maintain the client’s state. However, the server responds to the client’s requests using the context provided by the client. In addition, the client sends the session identifier to the server. As a result, we can identify the ongoing session on the server using a session identifier.
6. State and describe different HTTP Status Codes.
When a client sends a request, the server issues a response in the form of an HTTP status code. HTTP has five different status codes, as listed below:
- 1xx: informational response – These codes specify that the server received the request and continues to process it.
- 2xx: successful responses – These codes represent that the server received the request, understood it, and accepted it.
- 3xx: redirects – These HTTP response status codes specify that the server has to carry out further actions to finish the HTTP request.
- 4xx: client errors – The request by the client is syntactically incorrect and cannot be processed.
- 5xx: server errors – The server is not able to process the valid and syntactically correct request.
Some generic HTTP status codes are mentioned below:
- 200: used for OK or success.
- 201: specified CREATED.
- 304: NOT MODIFIED.
- 400: BAD REQUEST.
- 401: FORBIDDEN.
- 404: NOT FOUND.
- 500: INTERNAL SERVER ERROR.
- 502: BAD GATEWAY.
7. Explain Options in the REST architecture.
Options in RESTful Web Services enable the REST client to determine and decide which HTTP Method to use for the resource recognized by the Uniform Resource Identifier (URI). In addition, we can utilize Options in the REST architecture for initiating the Cross-Origin Resource Sharing (CROS) request.
8. State and explain HTTP methods.
HTTP methods, also called HTTP Verbs, are responsible for performing CRUD operations. CRUD in the REST architecture stands for creating, reading, updating, and deleting operations.
Here are some of the most commonly used HTTP methods:
The GET method can perform a read-only operation. It fetches the desired information from the REST server.
We use the POST method to generate new resources on the server. However, this method produces a secondary resource to any other resource, i.e., a child resource to any existing resource.
The PATCH method enables us to make alterations or modifications to the resource.
When we wish to delete any resource from the server, we use the DELETE method.
With the PUT method, we can update the resource or replace it with the other.
The OPTIONS method provides a list of options supported by resources on the server.
When we need metadata information about a request URL, we use the HEAD method.
9. Are there any drawbacks of RESTful Web Services? If yes, state them.
Yes, RESTful Web Services have certain drawbacks that are as follows:
- We know that RESTful Web Services obey the idea of statelessness. Therefore, the server is not acquainted with the client’s status. As a result, it becomes challenging to maintain sessions; it is the client’s responsibility to pass the session-id to the server.
- There are no security impositions by REST. Therefore, RESTful Web Services are not feasible for exchanging confidential data between the client and the server.
10. Explain the concept of ‘Messaging’ in RESTful Web Services.
In RESTful Web Services, messaging means sending an HTTP request to the REST server by the REST client and receiving an HTTP response.
11. Explain the variation between the POST and PUT HTTP Methods.
The PUT method in the REST architecture is used for updating existing resources present on the REST server or replacing them with others. In addition, this method is designed to locate a resource at its respective URI. However, if a resource is already at its URI, PUT updates it. Moreover, if there is no resource, PUT creates one.
The POST Method in REST transmits information to the URI and looks forward to the resource present at that URI to respond to the request.
Additionally, the PUT method does not affect resources on the server even if we invoked it multiple times. On the contrary, the POST method creates new resources every time you invoke them.
12. What are the dissimilarities between SOAP and REST protocols?
The following table highlights some major differences between SOAP and REST:
|Its full form is REpresentational State Transfer.||Its full form is Simple Object Access Protocol.|
|It is a set of architectural principles used to develop web services.||SOAP is an API protocol that implements web services.|
|REST can utilize the SOAP protocol in its implementation.||SOAP cannot use the REST architecture because it is a protocol.|
|The REST client and the REST server are loosely connected.||The SOAP protocol allows a client and server to connect tightly.|
|The REST client and server can exchange information using various formats, such as MIME, text, XML, JSON, and many more.||SOAP only allows the XML format to interchange messages or data between the client and the server.|
|REST does not have specific security measures. Instead, security measures depend on the protocol used for communication.||Soap has its own security standards.|
13. List out some best practices to create URI for RESTful Web Services.
The following are some of the best tips that come in handy while generating URI for web services:
- Always use plural names while defining resources on the server.
- Use a hyphen or an underscore for longer names of resources. In addition, we must remember not to use spaces between resources’ names. For instance, instead of naming a resource ‘inventory management,’ we can name it either as ‘inventory management or ‘inventory_management.’
- Always name a URI in lower case.
- The URI should hold backward compatibility. In other words, the existing URI should redirect to the new one when it gets updates using the PUT method. To redirect, we use the HTTP status code 300.
- To represent the hierarchy between the resources, use a forward slash.
14. List out the best practices for designing a resource format.
While designing a resource’s format, the below points will help us do better:
- The REST client and the REST server should understand and use the resource’s representation format. As a result, the resource representation should be understandable.
- The resource format that we design should have a complete representation. In the case of resources containing other resources, their representation should involve both complex and simple structures.
- The resource format should have the ability to handle links between resources.
15. State some dissimilarities between REST and AJAX.
Some significant differences between AJAX and REST are as follows:
|It is an architectural design for creating client-server applications.||It is used to update UI dynamically without reloading the page.|
|Constant interaction between the REST client and the REST server is a must.||The interaction between the client and server does not need to be constant.|
16. List and describe the HTTP Request’s core components.
The HTTP Request has five significant components, as explained below:
- Method or Verb:
The HTTP Request has various methods or verbs, such as PUT, POST, DELETE, GET, OPTIONS, and PATCH.
- HTTP Version:
It represents the current version of the HTTP protocol. For instance, one of the HTTP versions is HTTP v1.1.
Uniform Resource Identifier (URI) identifies resources uniquely on the server.
- Request Header:
The header of the HTTP Request consists of request metadata, such as message format, client type, cache settings, etc.
- Request Body:
The body of the HTTP Request includes the original message that is to be transmitted to the REST server.
17. Explain different components of HTTP Response.
HTTP Response has four components that are:
- Response Status Code
The server transmits a response status code to the request sent by the REST client. For instance, the status code 200 specifies a successful response.
- HTTP Version:
It represents the current version of the HTTP protocol.
- Response Header:
This component holds the response message’s metadata, such as content type, content length, server type, response date, etc.
- Response Body:
It consists of the actual response or resource transmitted by the REST server.
18. Explain and define Addressing in the context of REST.
Locating a resource or resources present on the REST server using Uniform Resource Identifiers (URIs) is called Addressing. The process of Addressing in the RESTful Web Services is similar to locating a person’s address. As we use URIs for addressing, the general format of it is shown below:
19. State pros and cons of Statelessness.
Statelessness in RESTful Web Services refers to the situation where the client’s status is kept isolated or never maintained by the server. There are some pros and cons of statelessness that are as follows:
- Each method involved in the communication process is independent. Therefore, no methods have dependencies among them.
- The entire communication process in the REST architecture is simple because the previous communication between the REST client and the REST server is not preserved.
- The web service requires a little information about the REST client’s status whenever the client processes the HTTP request.
20. State limitations for RESTful Web Services.
Below are some crucial restrictions for RESTful Web Services:
- The first constraint is that every REST client and server should have particular concerns, as it will help us maintain the application’s modularity. Moreover, it helps to enhance an application’s scalability and reduce complexity.
- The next constraint for RESTful Web Services is that the data exchange between the REST client and the REST server should be stateless. In other words, information about the previous communication cannot be used.
- It is essential to cache the HTTP response. Thus, enabling us to use this copy whenever required to improve the REST server’s performance and scalability.
- A uniform interface is the fourth constraint, allowing us to comprehend client-server communication easily.
- Finally, the last constraint is that we must use the layered system to carry out the client-server interaction in RESTful Web Services.
Intermediate-Level REST API Interview Questions
21. Explain caching.
The process of storing the REST server response is called caching. We can use this cached copy whenever required. Therefore, generating the same response, again and again, is not necessary with caching. Also, the caching process enhances the server’s performance and reduces the load. Caching the response is only possible for the REST client.
22. Define Payload.
Payload is the request data that is stored in every HTTP message’s body. However, only the recipient receives the payload via the HTTP POST method. Furthermore, we can send as many messages in the form of a payload through the POST method. The only issue is that more data requires a longer time to process and faster bandwidth.
23. Is there any restriction on the payload size sent via the POST method?
No, there is no limitation on the payload size that is sent via the POST method. However, the higher the payload size, the greater the time required to process the request as well as higher bandwidth consumption. Also, payload size affects the server speed.
24. Can we send payload using GET and DELETE HTTP methods?
No, we cannot send the payload via the GET and DELETE methods because the payload is not the request parameter.
25. Explain idempotent and safe HTTP methods.
HTTP methods are the ones that do not change or alter the resources’ responses externally. Thus, we can invoke idempotent methods multiple times without changing resources’ responses. HTTP methods that are idempotent are OPTIONS, HEAD, GET, DELETE, and PUT.
HTTP methods that do not modify or change resources internally are safe methods. Thus, we can cache and fetch safe methods without harming resources on the server. HTTP safe methods are PATCH and POST.
26. Which HTTP response provides information regarding the date and time when a resource was created or modified?
The Data Header of the HTTP response header gives the date and time of the resource when it was developed, and the Last Modified Header gives the date and time when the resource was last modified.
27. Name the HTTP response headers that give information about control over caching and expiration date and time of caching.
The Cache-Control Header offers information about control over caching, and the Expires Header provides caching’s expiration date and time.
28. Explain JAX-RS.
Java API for RESTful Web Services is the full form of JAX-RS. It is a programming language API based on the Java language that provides strong support for implementing RESTful Web Services. The latest version of JAX-RS is 3.0. JAX-RS uses Java SE 5’s annotations to make the development of Web Services simple and efficient.
29. How do you test RESTful Web Services?
Various Web testing tools are available to test RESTful Web Services, such as Katalon Studio, Postman, etc. Katalon Studio is one of the best API testing tools, enabling us to test APIs without previous experience. In addition, it ensures high test coverage and provides detailed test reports.
The next testing tool is Postman. It is used as a plugin in the Google Chrome browser. In addition, it is one of the sturdiest HTTP clients used for testing web services. With Postman, we can transmit requests to endpoints and receive responses in the form of JSON or XML.
30. Explain the differences between REST and Web Socket.
REST and Web Socket are two distinct protocols used for developing Web Services. The following table describes the key differences between REST and Web Socket:
|The REST architecture obeys the stateless protocol, i.e., there is no need to store session-based information.||Web Socket follows the stateful protocol, meaning we need to store all session-based information.|
|The interchange of data between the REST client and the REST Server is unidirectional. In other words, either a client or the server can transmit the message at a time.||Both the server and the client can transmit their messages simultaneously. Therefore, the web socket supports bidirectional communication.|
|REST follows the request-response architecture.||Web Socket follows the full-duplex pattern.|
|Communication is relatively slower.||Communication in Web Socket is more rapid and faster.|
|It uses HTTP methods to receive responses.||It uses the system’s port number and IP address to receive responses.|
REST is one of the easily scalable and reliable architectures used for developing APIs. It is highly scalable because of the separation between the REST server and the REST client. In addition, web services developed using the REST architecture are in great demand today. Therefore, the demand for REST API developers is increasing accordingly.
This article consists of some popular and frequently asked REST API interview questions and answers. If you desire to become a REST API developer, the above questions and answers will assist you in clearing the interview. However, most of these questions are meant for beginners who want to appear for an interview of the REST API developer.
People are also reading: