REST is an architecture for providing access to data over a network through an API hackerrank

Q 1- Which of the following is true about REST?A- In REST architecture, a REST Server simply provides access to resources and RESTclient accesses and presents the resources.- Each resource is identified by URIs/ global IDs.- REST uses various representations to represent a resource like text, JSON and XML.- All of the above.Answer : DExplainationAll of the above options are correct.BCD


👉 Download PDF

1) Explain what is REST and RESTFUL?

REST represents REpresentational State Transfer; it is a relatively new aspect of writing web API.

RESTFUL is referred for web services written by applying REST architectural concept are called RESTful services, it focuses on system resources and how state of resource should be transported over HTTP protocol to different clients written in different language. In RESTFUL web service HTTP methods like GET, POST, PUT and DELETE can be used to perform CRUD operations.

2) Explain the architectural style for creating web API?

The architectural style for creating web api are

  • HTTP for client server communication
  • XML/JSON as formatting language
  • Simple URI as the address for the services
  • Stateless communication

3) Mention what tools are required to test your web API?

SOAPUI tool for SOAP WS and Firefox “poster” plugin for RESTFUL services.

4) Mention what are the HTTP methods supported by REST?

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 resource
  • PUT: At the request URL it update the resource
  • DELETE: At the request URL it removes the resource
  • OPTIONS: It indicates which techniques are supported
  • HEAD: About the request URL it returns meta information

5) Mention whether you can use GET request instead of PUT to create a resource?

No, you are not supposed to use PUT for GET. GET operations should only have view rights, while PUT resource is used for updating a data.

6) Mention what are resources in a REST architecture?

Resources are identified by logical URLs; it is the key element of a RESTful design. Unlike, SOAP web services in REST, you view the product data as a resource and this resource should contain all the required information.

7) Mention what is the difference between AJAX and REST?

AJAX REST
  • In Ajax, the request are sent to the server by using XMLHttpRequest objects. The response is used by the JavaScript code to dynamically alter the current page.
  • REST have a URL structure and a request/response pattern the revolve around the use of resources.
  • Ajax is a set of technology; it is a technique of dynamically updating parts of UI without having to reload the page.
  • REST is a type of software architecture and a method for users to request data or information from servers.
  • Ajax eliminates the interaction between the customer and server asynchronously.
  • REST requires the interaction between the customer and server.

7) Mention some key characteristics of REST?

Some key characteristics of REST includes

  • REST is stateless, therefore the SERVER has no state (or session data)
  • With a well-applied REST API, the server could be restarted between two calls as every data is passed to the server
  • Web service mostly uses POST method to make operations, whereas REST uses GET to access resources


8) Mention what are the different application integration styles?

The different integration styles include

  • Shared database
  • Batch file transfer
  • Invoking remote procedure (RPC)
  • Swapping asynchronous messages over a message oriented middle-ware (MOM)

9) Explain how JAXB related to RESTful web API?

JAXB stands for java arch for XML binding.

10) Mention what is the difference between PUT and POST?

“PUT” 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

11) Mention which markup language can be used in restful web api?

JSON and XML are the two markup language that can be used in restful web api

12) Mention what is the difference between RPC or document style web services? How you determine to which one to choose?

In document style web services, we can transport an XML message as part of SOAP request which is not possible in RPC style web service. Document style web service is most appropriate in some application where XML message behaves as document and content of that document can alter and intention of web service does not rely on the content of XML message.

13) Mention what is JAX-WS and JAX-RS?

Both JAX-WS and JAX-RS are libraries (APIs) for doing communication in various ways in Java. JAX-WS is a library that can be used to do SOAP communication in JAVA, and JAX-RS lets you do the REST communication in JAVA.

14) List out the tools or API for developing or testing web api?

Testing tools for web services for REST APIs includes

  • Spring REST web service using MVC
  • Jersey API
  • CXF
  • Axis
  • Restlet,


15) Mention what is the difference between SOAP and REST?

SOAP REST
  • SOAP is a protocol through which two computer communicates by sharing XML document.
  • Rest is a service architecture and design for network-based software architectures.
  • REST supports many different data formats
  • SOAP based reads cannot be cached
  • SOAP is like custom desktop application, closely connected to the server
  • A REST client is more like a browser; it knows how to standardized methods and an application has to fit inside it
  • It runs on HTTP but envelopes the message
  • It uses the HTTP headers to hold meta information

REST stands for REpresentational State Transfer and API stands for Application Program Interface. REST is a software architectural style that defines the set of rules to be used for creating web services. Web services which follow the REST architectural style are known as RESTful web services. It allows requesting systems to access and manipulate web resources by using a uniform and predefined set of rules. Interaction in REST based systems happen through Internet’s Hypertext Transfer Protocol (HTTP). 

A Restful system consists of a:



  • client who requests for the resources.
  • server who has the resources.

It is important to create REST API according to industry standards which results in ease of development and increase client adoption. 

Architectural Constraints of RESTful API: There are six architectural constraints which makes any web service are listed below:

  • Uniform Interface
  • Stateless
  • Cacheable
  • Client-Server
  • Layered System
  • Code on Demand

The only optional constraint of REST architecture is code on demand. If a service violates any other constraint, it cannot strictly be referred to as RESTful. 

Uniform Interface: It is a key constraint that differentiate between a REST API and Non-REST API. It suggests that there should be an uniform way of interacting with a given server irrespective of device or type of application (website, mobile app). 

There are four guidelines principle of Uniform Interface are:

  • Resource-Based: Individual resources are identified in requests. For example: API/users.
  • Manipulation of Resources Through Representations: Client has representation of resource and it contains enough information to modify or delete the resource on the server, provided it has permission to do so. Example: Usually user get a user id when user request for a list of users and then use that id to delete or modify that particular user.
  • Self-descriptive Messages: Each message includes enough information to describe how to process the message so that server can easily analyses the request.
  • Hypermedia as the Engine of Application State (HATEOAS): It need to include links for each response so that client can discover other resources easily.

Stateless: It means that the necessary state to handle the request is contained within the request itself and server would not store anything related to the session. In REST, the client must include all information for the server to fulfill the request whether as a part of query params, headers or URI. Statelessness enables greater availability since the server does not have to maintain, update or communicate that session state. There is a drawback when the client need to send too much data to the server so it reduces the scope of network optimization and requires more bandwidth.

Cacheable: Every response should include whether the response is cacheable or not and for how much duration responses can be cached at the client side. Client will return the data from its cache for any subsequent request and there would be no need to send the request again to the server. A well-managed caching partially or completely eliminates some client–server interactions, further improving availability and performance. But sometime there are chances that user may receive stale data. 

Client-Server: REST application should have a client-server architecture. A Client is someone who is requesting resources and are not concerned with data storage, which remains internal to each server, and server is someone who holds the resources and are not concerned with the user interface or user state. They can evolve independently. Client doesn’t need to know anything about business logic and server doesn’t need to know anything about frontend UI. 

Layered system: An application architecture needs to be composed of multiple layers. Each layer doesn’t know any thing about any layer other than that of immediate layer and there can be lot of intermediate servers between client and the end server. Intermediary servers may improve system availability by enabling load-balancing and by providing shared caches. 

Code on demand: It is an optional feature. According to this, servers can also provide executable code to the client. The examples of code on demand may include the compiled components such as Java applets and client-side scripts such as JavaScript. 

Rules of REST API: There are certain rules which should be kept in mind while creating REST API endpoints.

  • REST is based on the resource or noun instead of action or verb based. It means that a URI of a REST API should always end with a noun. Example: /api/users is a good example, but /api?type=users is a bad example of creating a REST API.
  • HTTP verbs are used to identify the action. Some of the HTTP verbs are – GET, PUT, POST, DELETE, GET, PATCH.
  • A web application should be organized into resources like users and then uses HTTP verbs like – GET, PUT, POST, DELETE to modify those resources. And as a developer it should be clear that what needs to be done just by looking at the endpoint and HTTP method used.
URI HTTP verb Description
api/users GET Get all users
api/users/new GET Show form for adding new user
api/users POST Add a user
api/users/1 PUT Update a user with id = 1
api/users/1/edit GET Show edit form for user with id = 1
api/users/1 DELETE Delete a user with id = 1
api/users/1 GET Get a user with id = 1
  • Always use plurals in URL to keep an API URI consistent throughout the application.
  • Send a proper HTTP code to indicate a success or error status.

Note : You can easily use GET and POST but in order to use PUT and DELETE you will need to install method override. You can do this by following below code :

npm install method-override --save

This simply require this package in your code by writing :

var methodOverride = require("method-override");

Now you can easily use PUT and DELETE routes :

app.use(methodOverride("_method"));

HTTP verbs: Some of the common HTTP methods/verbs are described below:

  • GET: Retrieves one or more resources identified by the request URI and it can cache the information receive.
  • POST: Create a resource from the submission of a request and response is not cacheable in this case. This method is unsafe if no security is applied to the endpoint as it would allow anyone to create a random resource by submission.
  • PUT: Update an existing resource on the server specified by the request URI.
  • DELETE: Delete an existing resource on the server specified by the request URI. It always return an appropriate HTTP status for every request.
  • GET, PUT, DELETE methods are also known as Idempotent methods. Applying an operation once or applying it multiple times has the same effect. Example: Delete any resource from the server and it succeeds with 200 OK and then try again to delete that resource than it will display an error message 410 GONE.

Article Tags :