The restful API is a very common API development mechanism to access server data. The full-stack application has a two-layer one is front-end and the second is the backend. The back-end is an API that might be written in any programming language like PHP, Golang, Python, etc.
In this tutorial, You will find the collection of the rest API questions and answers, which help to rest API interviews and improve your knowledge.
Table of Contents
What is Rest API?
REST is aka Representational State Transfer that helps for stateless client-server communication. The server can be easily accessed over the network by Uniform Resource Identifier(URI).
The main benefit of Restful API is high scalability and maintainability, easy to create APIs, etc.
What is the use of RESTful API
When we create the rest API that implements REST architecture over the HTTP method, that type of API called RESTful API. The main features of RESTful API are scalability and maintainability. You can create a RESTFUL web service over HTTP methods like GET, POST, PUT and DELETE , that can be used to perform CRUD operations. You can create RESTful API on various programming languages etc.
How To Test Rest API
You can test RESTful API using Postman, Vrest etc. The HTTP get call also test using a Web browser but post-call need to test using API Tool.
How To send Authorization
We can pass any token into the header of the rest of API, The simple way to deal with authentication is to use HTTP basic authentication. We add ‘username:password
‘ encoded in base64 into Authorization key lie Authorization: Basic YgsrsvR==
.
How To Create Custom Key Into Header?
We can add a custom key to the Rest API Request header and assign it to the request object, which can then be accessed via the request header object on the server.
What Are the Common Data Format of RESTful API?
The data format is used to exchange data between the client and the server. The Request and Response data formats would be JSON, YML, HTML, or XML. JSON data format is commonly used to send and receive data from the server.
What is the Cache in Rest API?
This helps to reduce server load while increasing the server’s scalability and performance. Caching is the process of storing server responses so that a cached copy can be used instead of generating the same response again when needed.
What is a Cache-Control header?
There are the following options available to cache API Data-
- Public: This helps to cached data by any intermediate components between the client and server.
- Private: The Private header key help to cache data into the client side.
- no Cache : This means the REST API will cache any data nor client or server.
What are Different Type HTTP methods?
- GET: This is a read-only operation used to fetch the information from the server.
- PUT: This operation is used for the updation of any existing information on the server.
- POST: This operation is used for creating new information on the server.
- DELETE: This operation is used for deleting any resource on the server.
- OPTIONS: This operation uses the get the list of any supported options of resources that are available on the server.
What is the difference between the PUT method and the POST method?
The PUT method updates an existing record on the server, whereas the POST method creates a new record. The PUT response is always the same, whereas the POST response changes depending on the request.
What are HTTP Status and Some Common HTTP status codes?
The HTTP Status code notifies the client, the request has been processed, accepted, success or failure, What was the reason for the failed request.
- Code 200: This indicates success.
- Code 201: This indicates resource has been successfully created.
- Code 204: This indicates that there is no content in the response body.
- Code 404: This indicates that there is no method available.
You can get more information on HTTP Status Code.
What is Microservices?
The microsystem is a very popular architecture to create restful APIs.
- Microservices can adapt easily to other frameworks or technologies.
- Failure of a single process does not affect the entire system.
- Provides support to big enterprises as well as small teams.
- Microservices can be deployed independently and in relatively less time.
What is URI?
URI stands for Uniform Resource Identifier which is used for identifying each resource of the REST architecture.
The format of URI is.
<protocol>://<service-name>/<ResourceType>/<ResourceID>
There are 2 types of URI:
URN: Uniform Resource Name identifies the resource by means of a name that is both unique and persistent. It starts with the urn.
URL: Uniform Resource Locator has the information regarding fetching of a resource from its location.Its start with HTTP, HTTPS, FTP, file, etc
What is the stateless REST API?
The REST architecture is designed in such a way that the client state is not maintained on the server. This is known as statelessness. The client is responsible for storing and handling all application state-related information on client-side.
What is the difference between SOAP and REST?
There are the following differences between SOAP and REST.
SOAP | REST |
SOAP is slower than REST | REST is faster than SOAP |
SOAP is a protocol that allows two computers to communicate by sharing an XML document. | Rest is a network-based software architecture service architecture and design. |
SOAP only supports XML | REST supports a wide range of data formats. |
SOAP-based reads cannot be cacheable. | REST reads can be cached |
SOAP is similar to a custom desktop application that is tightly connected to the server. SOAP is slower than REST. | A REST client functions more like a browser; it understands how to use standardized methods, and an application must fit within it. |
It runs on HTTP but envelopes the message. | It stores meta information in HTTP headers. |