about http and rest
TRANSCRIPT
HTTPThe protocol that allows for sending docs back and forth on the web.
server roleclient role
server roleclient role
initiates interaction
responds
header
body
header
body
includes metadata and HTTP methods
includes data you want to transfer (text, pics, HTML, XML)
The response specifies the content type of the body
in the Content Type field (e.g. text/html or application/json)
HTTP REQUEST METHODSGET POST PUT DELETE
HTTP REQUEST METHODSGET POST PUT DELETE
queries the representation of a resource
deletes resources
changes the state ofa resource
produces new or replaces content of existing resources (idempotent)
RESTRepresentational State Transfer:using the principles of the World Wide Web to build applications
RESTweb services try to leverage HTTP in its entirety using specific architectural principles
ful
common perspectiveson architectural design
2
Designer starts with nothing (blank) and builds an architecture from familiar components.
Designer starts with the system needs and applies constraints to elements of the system.
1
22
2REST
Designer starts with the system needs and applies constraints to elements of the system.
CONSTRAINTS
1 2 3
4 5 6
Client-server Architecture1A server component offering services, listens for requests upon these services. A client component desires that a service be performed, sends a request to the server via a connector.
serverclient
triggering process reactionary process
server roleclient role
initiates interaction by sending a request for a service to be performed
responds to the request by either performing the service or rejecting it
This separation allows for the two components to evolve independently, which increases scalability.
Stateless Communication 2Each request from the client must contain all necessary information to understand the request.
This constraint induces:
• Visibility – need to look at only one request to get the full nature of the request
• Reliability – eases the task of recovering from failures
• Scalability – not having to store data between requests allows the server to free resources
Cache3Cache constraints require that the data within a response to a request be labeled as cacheable or non-cacheable. If a response is cacheable, a client cache is given the right to reuse the response data for later, equivalent requests.
Cache constraints eliminate some interactions and improve efficiency and scalability. Cache can decrease reliability because of stale data.
Uniform Interface41. Identification of resources
A resource is any information that can be named. An example of a resource is the current weather in Austin, TX. Resource identification requires the same authority who maintains the reference to a resource to also be responsible for preserving meaning of that resource.
2. Manipulation of resources through representations
The resources must be manipulated via representations. A client has no access to a resource directly, it can only send and receive representations from the server. (An example of a representation is an html page with a PNG image of the current weather in Austin, TX.)
Data Element Modern Web Examples
resource the intended conceptual target of a hypertext reference
resource identifier URL, URN
representation HTML document, JPEG image
representation metadata media type, last-modified time
resource metadata source link, alternates, vary
control data if-modified-since, cache-control
Connector Modern Web Examples
client libwww, libwww-perl
server libwww, Apache, API, NSAPI
cache browser cache, Akamai cache network
resolver bind (DNS lookup library)
tunnel SOCKS, SSL after HTTP CONNECT
3. Self-descriptive messages
States that all messages must include metadata which describe the meaning of the message.
4. Hypermedia as the engine of application state
The steps in a REST architecture must be invoked through hypermedia. More specifically, in order for an application’s process to move a step, it must invoke that next step from a reference inside the current representation.
Render the data where it’s located and send a fixed-format image to the recipient
Send the raw data to the recipient along with metadata that describes the data type so that the recipient can choose their own rendering engine
1
33options for a distributed hypermedia architect
Encapsulate the data with a rendering engine and send both to the recipient
2
Layered System5Layered system style allows an architecture to be composed of hierarchical layers by constraining component behavior so each component cannot ‘see’ beyond the immediate layer with which they are interacting.
Layered system style helps reduce complexity and promote independence. Layers can be used to protect new services from legacy clients. They can also add overhead.
Code on Demand6REST allows client functionality to be extended by downloading and executing code in the form of scripts.
TESTINGRESTful APIs (with forms)
Simple REST Client is a plugin for Chrome. Once installed, you should have a button in the toolbar.
Download Simple REST Client
• The API POST URL• A POST string• Content Type header
What else do you need?
THE END.