REST API is extensively considered as the standard protocol for the web APIs. In one of the largest independent and publicly available directories for APIs, the ProgrammableWeb, REST API represents 69% of the share of all Internet APIs. Follow along to learn and refresh 26 most advanced REST API Interview Questions and Answers you may face on your next web developer interview.
REST is the acronym for REpresentational State Transfer. REST is an architectural style for developing applications that can be accessed over the network. REST architectural style was brought in light by Roy Fielding in his doctoral thesis in 2000.
REST is a stateless client-server architecture where web services are resources and can be identified by their URIs. Client applications can use HTTP GET/POST methods to invoke Restful web services. REST doesn’t specify any specific protocol to use, but in almost all cases it’s used over HTTP/HTTPS.
When compared to SOAP web services, these are lightweight and doesn’t follow any standard. We can use XML, JSON, text or any other type of data for request and response.
Some key characteristics of REST includes
Ajax
XMLHttpRequest objects. The response is used by the JavaScript code to dynamically alter the current pageREST
Some of the advantages of REST web services are:
Resource is the fundamental concept of Restful architecture. A resource is an object with:
Resources are identified with:
URI stands for Uniform Resource Identifier. Each resource in REST architecture is identified by its URI. Purpose of an URI is to locate a resource(s) on the server hosting the web service.
A URI is of following format:
<protocol>://<service-name>/<ResourceType>/<ResourceID>HTTP methods supported by REST are:
GET: It requests a resource at the request URL. It should not contain a request body as it will be discarded. Maybe it can be cached locally or on the server.POST: It submits information to the service for processing; it should typically return the modified or new resourcePUT: At the request URL it update the resourceDELETE: At the request URL it removes the resourceOPTIONS: It indicates which techniques are supportedHEAD: About the request URL it returns meta informationPUT puts a file or resource at a particular URI and exactly at that URI. If there is already a file or resource at that URI, PUT changes that file or resource. If there is no resource or file there, PUT makes one
POST sends data to a particular URI and expects the resource at that URI to deal with the request. The web server at this point can decide what to do with the data in the context of specified resource
PUT is idempotent meaning, invoking it any number of times will not have an impact on resources.
However, POST is not idempotent, meaning if you invoke POST multiple times it keeps creating more resources
Some of the disadvantages of REST are:
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.
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.
Following is the disadvantage of statelessness in RESTful web services:
To ensure reliable transactions and secure confidential information, web services requires very high level of security which can be only achieved through Entrust Secure Transaction Platform. Security issues for web services are broadly divided into three sections as described below
1) Confidentiality: A single web service can have multiple applications and their service path contains a potential weak link at its nodes. Whenever messages or say XML requests are sent by the client along with the service path to the server, they must be encrypted. Thus, maintaining the confidentiality of the communication is a must.
2) Authentication: Authentication is basically performed to verify the identity of the users as well as ensuring that the user using the web service has the right to use or not? Authentication is also done to track user’s activity. There are several options that can be considered for this purpose
3) Network Security: This is a serious issue which requires tools to filter web service traffic.
Addressing refers to locating a resource or multiple resources lying on the server. It is analogous to locate a postal address of a person.
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.
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.
Consider following status codes:
Accept headers tells web service what kind of response client is accepting, so if a web service is capable of sending response in XML and JSON format and client sends Accept header as application/xml then XML response will be sent. For Accept header application/json, server will send the JSON response.
Content-Type header is used to tell server what is the format of data being sent in the request. If Content-Type header is application/xml then server will try to parse it as XML data. This header is useful in HTTP Post and Put requests.
GraphQL and microservices are a perfect fit, because GraphQL hides the fact that you have a microservice architecture from the clients. From a backend perspective, you want to split everything into microservices, but from a frontend perspective, you would like all your data to come from a single API. Using GraphQL is the best way I know of that lets you do both. It lets you split up your backend into microservices, while still providing a single API to all your application, and allowing joins across data from different services.
Rust has been Stack Overflow’s most loved language for four years in a row and emerged as a compelling language choice for both backend and system developers, offering a unique combination of memory safety, performance, concurrency without Data races...
Clean Architecture provides a clear and modular structure for building software systems, separating business rules from implementation details. It promotes maintainability by allowing for easier updates and changes to specific components without affe...
Azure Service Bus is a crucial component for Azure cloud developers as it provides reliable and scalable messaging capabilities. It enables decoupled communication between different components of a distributed system, promoting flexibility and resili...