Rest With Spring: Description
Rest With Spring: Description
Table of Content
1. The Basic of Rest with Spring ........................................................................................ 2
1.1. Constraints ............................................................................................................. 4
1.2. Terminologies .......................................................................................................... 4
1|P a g e
Java Core 8 Pascal Mihai Andrei
2|P a g e
Java Core 8 Pascal Mihai Andrei
Architecture Principles:
Everything is a resource in REST architecture style, data and functionality are considered resources
and are accessed using Uniform Resource Identified (URI), typically links inn the Web.
Every resource is identified by a Unique Identifier (URI).
Use simple and uniform interfaces.
Communication is done by representation. So Rest will send a representation in the form of XML or
JSON or text or any other form on the clients request
Be stateless.
3|P a g e
Java Core 8 Pascal Mihai Andrei
he wants, so the user uses some intermediate service to access this resource and this is the job of an API
which is waiter in our case, so a REST API accesses this resource on the clients request and then responds
this representation of the result to the client.
For example, if a client wanted to invoke a web service that lists all of the quizzes available here at
TechTarget, the URL to the web service would look something like this:
www.techtarget.com/restfulapi/quizzes. When invoked, the web service might respond with the
following JSON string listing all of the available quizzes, one of which is about DevOps:
{ "quizzes" : [ "Java", "DevOps", "IoT"] }.
To get the DevOps quiz, the web service might be called using the following URL:
www.techtarget.com/restfulapi/quizzes/DevOps.
Invoking this URL would return a JSON string listing all of the questions in the DevOps quiz. To get
an individual question from the quiz, the number of the question would be added to the URL. So, to get the
third question in the DevOps quiz, the following RESTful URL would be used:
www.techtarget.com/restfulapi/quizzes/DevOps/3.
Invoking that URL might return a JSON string such as the following:
{ "Question" : {"query":"What is your DevOps role?", "optionA":"Dev", "optionB":"Ops"} }.
1.1. Constraints
1) Client-Server This fundamental constraint enforces a separation of concerns and enables
independent evolution of the Client and the Server.
2) Stateless The communication between Client and Server must be stateless between requests.
First – the obvious part: each request from a client should contain all the necessary information for
the service to complete the request. Then, the more non-obvious part: all session state data should
then be returned to the client at the end of each request.
3) Cache All responses from the Server should be explicitly labeled as cacheable or non-cacheable.
Requests should pass through a Cache Component – which can partially or fully eliminate some
interactions with the Server. The results are improved efficiency and scalability by matching and
utilizing the already available huge infrastructure of the Web.
4) Interface / Uniform Contract The Service and all Clients must share a single uniform technical
interface. In order for that interface to be reusable by a wide range of Clients, it needs to provide
generic, high-level capabilities that are abstract enough to accommodate a broad range of
interactions.
5) Layered System This constraint builds on Client-Server Constraint to allow for Intermediaries /
Middleware. There intermediaries must be fully transparent for the Client. The interaction between
a Service and a Client should be consistent, regardless if the Client is communicating directly with
the ultimate receiver of a message or not. Similarly, the Service does not need to be aware of
whether the Client is itself acting as a service for other Clients or if it’s the actual origin. This kind of
information hiding greatly simplifies the distributed architecture of the system and allows individual
architectural layers to be deployed and evolved independently of specific service and consumers.
1.2. Terminologies
1) Resource The Resource is the key abstraction of information in REST. Any information that can
be named / identified via a unique, global id (the URI) – is a Resource.
2) Representation Any given Resource can have multiple Representations; these capture the
current state of the Resource in a specific format. At the lowest level, the Representation is “a
sequence of bytes, plus representation metadata to describe these bytes”.
3) Hypermedia Types There are several Hypermedia types we can use for our Representations, and
we can build our own if we need to. IMPORTANT: JSON is not a Hypermedia.
4|P a g e