10 REST API Basic Interview Questions

Abhishek Singh
Javarevisited
Published in
6 min readJul 17, 2023
Photo by Christopher Gower on Unsplash

1- What do you understand by RESTful Web Services?

RESTful web services are services that follow REST architecture.

REST stands for Representational State Transfer and uses HTTP protocol (web protocol) for implementation.

These services are lightweight, provide maintainability, scalability, support communication among multiple applications that are developed using
different programming languages.

They provide means of accessing resources present at server required for the client via the web browser by means of request headers, request body, response body, status codes, etc.

2- What is a REST Resource ?

Every content in the REST architecture is considered a resource.

The resource is analogous to the object in the object-oriented programming world.

They can either be represented as text files, HTML pages, images, or any other dynamic data.

The REST Server provides access to these resources whereas the REST client consumes (accesses and modifies) these resources. Every resource is identified globally by means of a URI.

3- What is URI ?

Uniform Resource Identifier is the full form of URI which is used for identifying each resource of the REST architecture.

URI is of the format:
<protocol>://<service-name>/<ResourceType>/<ResourceID>
There are 2 types of URI:

Image generated by the author

URN: Uniform Resource Name identifies the resource by means of a name that is
both unique and persistent.
URN doesn’t always specify where to locate the resource on the internet.
They are used as templates that are used by other parsers to identify the
resource.

These follow the urn scheme and usually prefixed with urn: .
Examples include urn:isbn:1234567890 is used for identification of book based on the ISBN number in a library application.
urn:mpeg:mpeg7:schema:2001 is the default namespace rules for metadata of MPEG-7 video.
Whenever a URN identifies a document, they are easily translated into a URL by using “resolver” aer which the document can be downloaded.

URL: Uniform Resource Locator has the information regarding fetching of a resource from its location.
Examples include:
http://abc.com/samplePage.html
ftp://sampleServer.com/sampleFile.zip
file:///home/interviewbit/sampleFile.txt

URLs start with a protocol (like p, http etc) and they have the information of the network hostname (sampleServer.com) and the path to the document(/samplePage.html). It can also have query parameters.

4- What are the features of RESTful Web Services ?

Every RESTful web service has the following features:

1- The service is based on the Client-Server model.

2- The service uses HTTP Protocol for fetching data/resources, query execution, or
any other functions.

3- The medium of communication between the client and server is called
“Messaging”.

4- Resources are accessible to the service by means of URIs.

5- It follows the statelessness concept where the client request and response are
not dependent on others and thereby provides total assurance of getting the
required data.

6- These services also use the concept of caching to minimize the server calls for
the same type of repeated requests.

7- These services can also use SOAP services as implementation protocol to REST
architectural pattern.

5- What is the concept of statelessness in REST ?

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 context is provided by the client to the server using which the server processes the client’s request.

The session on the server is identified by the session identifier sent by the client.

Image generated by the author

6- What do you understand by JAX-RS ?

As the name itself stands (JAX-RS= Java API for RESTful Web Services) is a Java-based specification defined by JEE for the implementation of RESTful services.

The JAX-RS library makes usage of annotations from Java 5 onwards to simplify the process of web services development. The latest version is 3.0 which was released in June 2020.

This specification also provides necessary support to create REST clients.

7- What are HTTP Status codes ?

These are the standard codes that refer to the predefined status of the task at the server.

Following are the status codes formats available:

1xx — represents informational responses
2xx — represents successful responses
3xx — represents redirects
4xx — represents client errors
5xx — represents server errors

Most commonly used status codes are:
200 — success/OK
201 — CREATED — used in POST or PUT methods.
304 — NOT MODIFIED — used in conditional GET requests to reduce the bandwidth use of the network. Here, the body of the response sent should be empty.
400 — BAD REQUEST — This can be due to validation errors or missing input data.
401 — FORBIDDEN — sent when the user does not have access (or is forbidden) to
the resource.
404 — NOT FOUND — Resource method is not available.
500 — INTERNAL SERVER ERROR — server threw some exceptions while running
the method.
502 — BAD GATEWAY — Server was not able to get the response from another
upstream server.

8- What are the HTTP Methods ?

HTTP Methods are also known as HTTP Verbs. They form a major portion of uniform interface restriction followed by the REST that specifies what action has to be followed to get the requested resource. Below are some examples of HTTP Methods:
GET: This is used for fetching details from the server and is basically a read-only operation.
POST: This method is used for the creation of new resources on the server.
PUT: This method is used to update the old/existing resource on the server or to replace the resource.
DELETE: This method is used to delete the resource on the server.
PATCH: This is used for modifying the resource on the server.
OPTIONS: This fetches the list of supported options of resources present on the server.

The POST, GET, PUT, DELETE corresponds to the create, read, update, delete operations which are most commonly called CRUD Operations.

Image generated by the author

GET, HEAD, OPTIONS are safe and idempotent methods whereas PUT and DELETE methods are only idempotent. POST and PATCH methods are neither safe nor idempotent.

9- Can you tell the disadvantages of RESTful web services ?

The disadvantages are:
1- As the services follow the idea of statelessness, it is not possible to maintain
sessions. (Session simulation responsibility lies on the client-side to pass the
session id)
2- REST does not impose security restrictions inherently. It inherits the security
measures of the protocols implementing it. Hence, care must be chosen to
implement security measures like integrating SSL/TLS based authentications,
etc.

10- Define Messaging in terms of RESTful web services ?

The technique of sending a message from the REST client to the REST server in the form of an HTTP request and the server responding back with the response as HTTP Response is called Messaging. The messages contained constitute the data and the metadata about the message.

Image generated by the author

--

--

Abhishek Singh
Javarevisited

I am a senior software engineer. I love to write articles on java. Follow my youtube channel - https://youtube.com/@DeveloperAbhishek