ECS781P
CLOUD COMPUTING
INTRODUCTION TO RESTFUL SERVICES
Lecturer: Dr. Sukhpal Singh Gill and Dr Ignacio Castro School of Electronic Engineering and Computer Science
Contents
RPC
Web services REST
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
A bit of History: RPC
The idea of networked applications is not new: the 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
Web Services A bit of History: RPC Web Services
RESTful Services
A bit of History: RPC
RPC aim (1970s): let distributed programming look no different from local procedure calls
– Preserveoriginal,unmodifiedclientandserver code
– RPCshouldgluetogetherclientandserver without changing behaviour of either
– Programmershouldn’thavetothinkabout network
Continued in 1990 with Java RMI
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
A bit of History: RPC
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
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
Web Services A bit of History: RPC Web Services
RESTful Services
A bit of History: RPC
The 8 fallacies of distributed computing:1 1) The network is reliable.
2) Latency is zero.
3) Bandwidth is infinite.
4) The network is secure.
5) Topologydoesn’tchange.
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
Web Services A bit of History: RPC Web Services
RESTful Services
A bit of History: RPC Critique of RPC:
Networked programs behave differently to single machine code
– Can’thaveperformanceexpectations
– Leadstomanydependencies,butcallsare
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
Web Services A bit of History: RPC Web Services
RESTful Services
A bit of History: RPC
All that said, there is still a point for using RPC, 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 A bit of History: RPC Web Services
RESTful Services
Web 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 A bit of History: RPC Web Services
RESTful Services
Web Services Standards
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 A bit of History: RPC Web Services
RESTful Services
Web Services Standards
Rise of Service-Oriented Architecture (SOA): 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 A bit of History: RPC Web Services
RESTful Services
Web Services Standards
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)
IETF publications over time
Heavy standardisation in the Internet (IETF)
Heavy standardisation in the Internet (IETF)
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Web Services Standards
The WSDL interface: Data types (schema), Interface: collection of operations, Input/output types, Binding: how to invoke that interface
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Web Services Standards For messaging protocol: SOAP
SOAP: Simple Object Access Protocol, is a messaging protocol specification for exchanging structured information in the implementation of web services
– ItusesXMLInformationSetforitsmessage format (to achieve platform and language independent)
– reliesonapplicationlayerprotocols,most often Hypertext Transfer Protocol (HTTP) or Simple Mail Transfer Protocol (SMTP), for message negotiation and transmission.
– SOAPcanexchangecompletedocumentsor call a remote procedure.
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Web Services Standards
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Web Services Standards
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Web Services Standards
Web Services – Critique:
– Very complex, redundant with HTTP functions
– Overlyambitious,toomanystandards, 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
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
REST
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
► REST is Stateless
State is stored in the server Stateless messages:
– All information required to provide the service is encoded in the message – greatsimplification
(extra) advantage: stateless middleboxes
– Proxyservers
– Caches*
– Loadbalancers*
REST
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
REST All information is abstracted as resources
REST 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
Web Services A bit of History: RPC Web Services
RESTful Services
REST REST Resources have identity
A resource is identified by its URI URI: Uniform Resource Identifier scheme:
scheme://host:port/path?queryString#fragment
URLs act as templates
– Partoftheaddressrepresentsthetypeofthe
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
Web Services A bit of History: RPC Web Services
RESTful Services
REST
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
– XMLSchemasallowtoverifycorrectformats
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
REST: Resource representation
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
REST 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
Web Services A bit of History: RPC Web Services
RESTful Services
REST
Sample REST interface: RESTbucks orders3 * demo: https://restcountries.eu/
3from Jim Webber, REST in Practice: Hypermedia and Systems Architecture
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Exchange of HTTP messages * demo: https://restcountries.eu/
REST
Cloud Computing
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→ApacheTomcat/Glassfish – Ruby→Rubyonrails
– …
REST
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
REST
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
Web Services A bit of History: RPC Web Services
RESTful Services
REST
Example: Mapping in Flask
Cloud Computing
Web Services A bit of History: RPC Web Services
RESTful Services
Other Resources
• RoyThomasFielding’sPhDThesis,CHAPTER 5: Representational State Transfer (REST)