Register Login

Rest Api Interview Questions and Answers

Updated Feb 19, 2019

What is REST API?

RESTful API (Representational State Transfer) is used to set some rules that need to be followed while developing web services. The architectural style is designed to use the current protocols. It is an API (Application Programming Interface) that uses HTTP for POST, DELETE and PUT commands.

What are some important characteristics of REST API?

The important characteristics of the RESTAPI are as follows:

  • It uses HTTP for POST, DELETE and PUT commands.
  • The architecture is based on the client and server model.
  • The architecture supports both XML and JSON, which is very helpful for developers as the flexibility of the development is more.
  • It is stateless as the server does not keep any data required to fulfil client requests. It makes the architecture scalable and visible.
  • It is properly documented for the benefit of the developers.

What is REST architecture?

RESThas the following architectural constraints for developing web services:

  • Client and server based – This means that the client and server application must not be dependent on each other and can work separately.
  • Statelessness – This means that the server does not keep any data required to fulfil client requests. It makes the architecture scalable and visible. Each request is treated as a new one.
  • Interface uniformity – The application interface must be uniform and the resources must be properly distributed for the users to access it easily.
  • Layered architecture – The RESTAPL lets the use of layered architecture for developing web services. It states that an application has to be layered where each layer has to be independent.

What is a REST web service?

Web services that are based on the RESTarchitecture are called RESTful web services. The architecture is used to build scalable and lightweight applications. It is used to set some rules that need to be followed while developing web services. The architectural style is designed to use the current protocols. It is an API (Application Programming Interface) that uses HTTP for POST, DELETE and PUT commands.

What is REST assured?

The RESTAssured is a Java library that is used by developers for creating tests for the RESTful web services. The library uses a DSL (Domain Specific Language). To access the web services, the HTTP requests can be customized as per our choice.

What is REST parameters? 

The RESTAPI has four types of parameters, which are:

  • Request parameters – These are submitted as JSON parameters present in the request.
  • Header parameters – These are present in the request header.
  • Query string parameters – These are provided at the endpoint of the query.
  • Path parameters – These are provided in the endpoint path.

Why REST is stateless?

RESTis stateless as the server does not keep track of the data required to complete the client requests. It makes the architecture scalable and visible. Each request is treated as a new one. As the past interactions with the client are not stored, the application becomes more simple.

What are RESTAPI endpoints?

An endpoint in REST can be considered as a URI that is used to send a request. It is an URL that is a part of the RESTAPI, where they are present for each resource.

How does RESTAPI work?

The RESTAPI provides the set of rules through which two applications on different systems communicate with each other. It implements the HTTP protocol for POST, DELETE, PUT operations. The API ensures that the proper resource is obtained through the corresponding URL.

How to call RESTAPI from java?

The RESTAPI can be called from Java using the following steps:

  • If the API is being called from Facebook or Twitter, the javax.net.ssl.HttpsURLConnection or java.net.HttpURLConnection can be used.
  • To obtain the result, the connection.getInputStream() method needs to be used.
  • The InputStream that will be received needs to be converted into a string, and later parsed into the JSON or XML object.
  • The Apache HTTP client can also be used.

How to consume RESTAPI in c#?

The different ways to consume RESTAPI though C#:

  • Using HTTPWebRequest class – This allows complete control over the development of the request. For the responses to the requests, it provides a container to accept them.
  • ServiceStack HTTP Utils – It is a very useful library deals with third party APIs HTTP utils.
  • HTTPClient class – This class is not dependent on a particular server, and it used to send multiple requests.
  • RestSharp NuGet package – It is a very useful library that allows the developers to work both asynchronously and synchronously.
  • WebClient class – This class works as a wrapper for the HTTPWebRequest class and reduces the excess writing of code for the developers.

How to call RESTAPI from android app?

The RESTAPI can be called from an Android application using the android-async-HTTP library.

Can RESTAPI be asynchronous?

Yes, RESTAPI can be asynchronous. However, the asynchronous or synchronous behaviour is dependent on the client who is making the request for the resource.

What are the RESTAPI headers?

The headers available for the RESTAPI are Accept and Content-Type is used for modifying the data inside the requests. They support the values:

  • Content-Type: application/json, application/XML
  • Accept: application/json, application/XML

How RESTAPI authentication works?

The RESTAPI authentication is based on the transfer of credentials from the client and the server. The basic authentication is based on the HTTP header. The HTTP header is used for providing the username and password that is encoded in base64. The following code is used:

GET / HTTP/1.1

Host: example.org

Authorization: Basic Zm9vOmJhcg==

The HMAC (Hash based Message Authentication) is used to send a hashed version of the passwords.

What is the difference between put and post method in RESTAPI?

The differences between PUT and POST are given below:

PUT

POST

It is used to develop or overwrite a resource.

It is used to modify or update a resource.

If the resource updated or created using PUT, the state of the resource remains the same even if the call is made again.

2 similar POST calls will result in two resources having similar information.

The responses to the calls made are cacheable.

The responses are not cacheable.

It can be used when a singular resource that is a part of the resource collection needs modification.

It is used to add a child resource under a resource collection.

What is REST client?

REST client applications are used to communicate with the resources related to the RESTful web servers. It is used to start communication by a request. The RESTCLient is a Python + wxWidgets Desktop application that can be used to easily establishing a communication with a RESTful web service. It supports PUT, POST, GET, DELETE. It is a Python based application.

How to use advanced REST client?

The Advanced RESTclient is used to develop HTTP requests and test them. The GET and POST method is used. The steps to use Advanced RESTclient are given below:

  • Install the Advanced RESTclient for Google Chrome.
  • In the specified area, enter the URL of your choice.
  • Choose the method option from PUT, POST, GET, DELETE etc. from the drop down beside it.
  • Select the header key and content of the header.
  • Provide the request for the content above.

What is the difference between soap and rest?

The differences between SOAP and RESTare provided below:

SOAP

REST

It is the Simple Object Access Protocol used for messaging based on XML.

It is an architecture used for laying out the protocols for web services.

It cannot use RESTas it is an architectural style and SOAP is a protocol.

RESTcan use SOAP as a protocol for web services.

The RPC method is used to call services.

The services are called using the URL path.

Data is transferred over HTTP, FTP, SMTP etc.

Data is transferred only using HTTP.

No support for error handling.

Built-in support for error handling.


Which framework is best for RESTAPI?

The best frameworks for RESTAPI are Spring MVC, ASP.Net, Flask, Django, JSF, Hibernate, Struts, Express.js and many others.

What is the use of delete in RESTAPI?

The DELETE is a request that is used for removing a resource.  


×