You are on page 1of 47

ECS781P

CLOUD COMPUTING
INTRODUCTION TO RESTFUL
SERVICES

Lecturer: Dr. Sukhpal Singh Gill


School of Electronic Engineering and Computer Science
Lectures ?
Lab ?
Coursework/Group ?
Important Announcements

• Quiz 1: Will be released soon, please keep eye


on QMPlus post.
• Deadline for Mini Project Submission: Week
12 (14th Dec, Thursday) at 10pm (No
Extension Please)
Contents

RPC Remote Procedure Call


Web services
REST
Cloud Computing

A bit of History: RPC


Web Services
A bit of History: RPC
Web Services The idea of networked applications is not new: the
RESTful Services vision of “distributed systems” was “transparency”:
that they should feel/appear/behave like not dis-
tributed.
- In particular, if you are writing a code that is
going to be run on a distributed system, it
should feel like you are writing that code for a
single “box”.
- So, e.g., the developers shouldn’t even notice
that when they are accessing a resource, it is
done over the network.
➢ This idea let to the development of RPC
protocol (Remote Procedure Call) in the 1970s.
Cloud Computing

A bit of History: RPC


Web Services
A bit of History: RPC
Web Services

RESTful Services

➢ RPC aim (1970s): let distributed programming


look no different from local procedure calls
- Preserve original, unmodified client and server
code
- RPC should glue together client and server
without changing behaviour of either
- Programmer shouldn’t have to think about
network
➢ Continued in 1990 with Java RMI
Cloud Computing

A bit of History: RPC


Web Services
A bit of History: RPC
Web Services

RESTful Services

Remote Procedure Calls


RPC at work
1. Client calls stub: the trick is to create stub
functions to make it appear to the user that
the call is local

A stub may simulate the behavior of existing code (such as a procedure on a remote machine) or be a
temporary substitute for yet-to-be-developed code.
Stub and Driver
RPC at work
2. Stub marshals params to network message
Marshalling = put parameters in a form suitable for transmission over a
network (serialized)
RPC at work
3. Network message sent to server
4. Receive message: send it to server stub
RPC at work
5. Unmarshal parameters, call server function
6. Return from server function
RPC at work
7. Marshal return value and send message
8. Transfer message over network
RPC at work
9. Receive message
10. Unmarshall return value to client
Cloud Computing

A bit of History: RPC


Web Services
A bit of History: RPC
Web Services
The 8 myths of distributed computing:1
RESTful Services
1) The network is reliable.
2) Latency is zero.
3) Bandwidth is infinite.
4) The network is secure.
5) Topology doesn’t change.
6) There is one administrator.
7) Transport cost is zero.
8) The network is homogeneous.
These challenges undermine the premise of RPC: you
cannot have the same result as you would have had
if you were on a single machine. RPC did not have
mechanism to deal with these issues.

1Peter Deux, James Gosling, 1996


Cloud Computing

A bit of History: RPC


Web Services
A bit of History: RPC
Web Services
Critique of RPC:
RESTful Services ➢ Networked programs behave differently to
single machine code
- Can’t have performance expectations
- Leads to many dependencies, but calls are
expensive
➢ Binary files (compiled) makes it hard to update
- Requires a compiler to generate stubs, and
transfer for each update
➢ Servers and clients are not decoupled and
cannot develop on their own
➢ Language-library specific
➢ Limitations in how data is transferred
(serialization)
Cloud Computing

A bit of History: RPC


Web Services
A bit of History: RPC
Web Services
➢ All that said, there is still a point for using RPC,
RESTful Services
as the promise of “transparency” is very
attractive for development.
➢ Newer libraries overcome many of the
problems
- e.g.: Thrift, Avro, protobuf,
Swagger, gPRC
➢ Its best use cases are scenarios where the
“fallacies” don’t hold strongly
- e.g. when we have a local homogeneous
network that has a high bandwidth, low
latency, high reliability, little change in
topology, not much concern for security or cost
in transport, and is centrally administered.
Contents

RPC
Web services
REST
Cloud Computing

Web Services
Web Services
A bit of History: RPC
Web Services

RESTful Services ➢ Somewhat as a reaction to limitations of RPC,


especially portability and interoperability, the
idea of web services was put forth (early 2000s)

➢ Web services (software components accessed


over a network) should be platform &
language independent, enabling
communication without worrying about
hardware/software/technology compatibility
- The clients and web services should be able to
communicate even though they are using
different hardware and are written in different
languages.
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services

RESTful Services

➢ Interoperability through XML documents


XML stands for eXtensible Markup
Language:2
- XML is a markup language much like HTML
- XML was designed to store and transport data
- XML was designed to be self-descriptive
XML is just a standard way to represent data by wrap-
ping information inside tags (that’s all!)

2https://www.w3schools.com/xml/xml whatis.asp
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services ➢ Rise of Service-Oriented Architecture (SOA):
RESTful Services
the interaction between clients and servers
being expressed (in a universal way) in terms
of service contracts
- I am a weather forecast service, if you want to
access my service, you need to send me a
message with two fields, country and date, etc.
➢ Key idea: service contracts in a
vendor-independent language: WSDL (Web
Services Description Language)
- Defines methods, interfaces
➢ Data representation: XML Schema (defining
the syntax of the XML messages, i.e. rules to
follow to create a specific XML message)
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services

RESTful Services

➢ Huge standardisation effort: Let’s put all the


effort to standardise all sorts of contracts
between clients and servers!
- WS-* extensions for security, messaging,
interoperability, . . .
(security was an area they were relatively the
best at: e.g. standardized many different ways
of authentication)
Heavy standardisation in the
Internet (IETF)

IETF
publications
over time
Heavy standardisation in the Internet
(IETF)
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services

RESTful Services

The WSDL interface: Data types (schema), Interface:


collection of operations, Input/output types, Binding:
how to invoke that interface
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services
For messaging protocol: SOAP
RESTful Services
➢ SOAP: Simple Object Access Protocol, is a
messaging protocol specification for
exchanging structured information in the
implementation of web services
- It uses XML Information Set for its message
format (to achieve platform and language
independent)
- relies on application layer protocols, most
often Hypertext Transfer Protocol (HTTP) or
Simple Mail Transfer Protocol (SMTP), for
message negotiation and transmission.
- SOAP can exchange complete documents or
call a remote procedure.
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services

RESTful Services
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services

RESTful Services
Cloud Computing

Web Services Standards


Web Services
A bit of History: RPC
Web Services

RESTful Services
Web Services – Critique:
- Very complex, redundant with HTTP functions
- Overly ambitious, too many standards,
interoperability issues
- Very inefficient for simple scenarios
- Big backlash from developers
That said:
➢ Still in use by large companies
➢ Comprehensive security features
Contents

RPC
Web services
REST
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services
RESTful applications
➢ REpresentational State Transfer.
- PhD thesis from one of the creators of HTTP:
Roy Fielding, 2000
➢ Client-server architecture for distributed
applications
➢ Not a specific protocol; a set of guidelines
➢ Http is perfectly suited for RESTful services
➢ Its popularity exploded in the late 2000s as a
reaction to WebServices / SOA
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services ► REST is Stateless


The server does not store any state about the client
session on the server-side. This restriction is called
Statelessness, means that every HTTP request
happens in complete isolation
➢ In REST applications, each request must contain
all the information necessary to be understood by
the server, rather than be dependent on the server
remembering prior requests.
➢ Storing session state on the server violates the
stateless constraint of the REST architecture. So,
the session state must be handled entirely by the
client.
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services ➢ Stateless messages:


- All information required to provide the service
is encoded in the message – great simplification
➢ (extra) advantage: stateless middleboxes
- Proxy servers
- Caches*
- Load balancers*
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services

REST Resources
➢ All information is abstracted as resources
➢ Resources are stored at the server, they are
stateful
➢ Resources have identity (can be referenced)
➢ Resources have a uniform access interface
➢ Client and server exchange resource
representations (eg XML or JSON format)
Cloud Computing

REST
Web Services
A bit of History: RPC
REST Resources have identity
Web Services
➢ A resource is identified by its URI
RESTful Services
➢ URI: Uniform Resource Identifier
➢ scheme:
scheme://host:port/path?queryString#fragment
➢ URLs act as templates
- Part of the address represents the type of the
resource, and the other part the individual
resource
- http://phones.com/whitepages/userPhone
➢ A URI can be further classified as a locator, a
name, or both.
➢ “Uniform Resource Locator” (URL): in addition
to identifying a resource, provide a means of
locating the resource by describing its primary
access mechanism (e.g., its network “location”).
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services
Resource representation
➢ Flexible format (XML, Json, something else)
- Content-Type: header
➢ JSON: JavaScript Object Notation, Javascript
mechanism for serialising objects
- Has become widely used, concise syntax,
flexible
➢ XML: eXtensible Markup Language
- Powerful
- XML Schemas allow to verify correct formats
Cloud Computing

REST: Resource
Web Services
A bit of History: RPC
Web Services
representation
RESTful Services
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services
The REST uniform Service interface
➢ Every resource has the same interface
(Analogous to Database CRUD)
- GET: Request a representation of the identified
resource
- POST: Create a new resource according to the
attached representation
- PUT: Update the representation of a resource
according to the attached representation
- DELETE: Delete the identified resource
* demo: browser + curl
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services

Sample REST interface: RESTbucks orders3

* demo: https://restcountries.eu/

3from Jim Webber, REST in Practice: Hypermedia and Systems Architecture


Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services

Exchange of HTTP messages

* demo: https://restcountries.eu/
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services Dynamic Web Servers


➢ Application Servers: Software listening to web
requests, and hosting specific server
applications
➢ The application server provides libraries for
apps
➢ Diversity of servers depending on technology
- Python → Flask, Django, Tornado
- JS → node.js
- Java → Apache Tomcat / Glassfish
- Ruby → Ruby on rails
- ...
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services

➢ Server-side applications are developed for a


specific application server
➢ Applications run inside an application server
➢ Applications register server paths / methods to
be handled by specific application code
➢ The application server receives the request,
handles the request message to the specific
application registered to answer
Cloud Computing

REST
Web Services
A bit of History: RPC
Web Services

RESTful Services

Example: Mapping in Flask


Cloud Computing

Other Resources
Web Services
A bit of History: RPC
Web Services

RESTful Services

• Roy Thomas Fielding’s PhD Thesis, CHAPTER


5: Representational State Transfer (REST)

You might also like