About HTTP and REST

31
HTTP The protocol that allows for sending docs back and forth on the web.

Transcript of About HTTP and REST

Page 1: About HTTP and REST

HTTPThe protocol that allows for sending docs back and forth on the web.

Page 2: About HTTP and REST

server roleclient role

Page 3: About HTTP and REST

server roleclient role

initiates interaction

responds

Page 4: About HTTP and REST

header

body

Page 5: About HTTP and REST

header

body

includes metadata and HTTP methods

includes data you want to transfer (text, pics, HTML, XML)

Page 6: About HTTP and REST

The response specifies the content type of the body

in the Content Type field (e.g. text/html or application/json)

Page 7: About HTTP and REST

HTTP REQUEST METHODSGET POST PUT DELETE

Page 8: About HTTP and REST

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)

Page 9: About HTTP and REST

RESTRepresentational State Transfer:using the principles of the World Wide Web to build applications

Page 10: About HTTP and REST

RESTweb services try to leverage HTTP in its entirety using specific architectural principles

ful

Page 11: About HTTP and REST

common perspectiveson architectural design

2

Page 12: About HTTP and REST

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

Page 13: About HTTP and REST

2REST

Designer starts with the system needs and applies constraints to elements of the system.

Page 14: About HTTP and REST

CONSTRAINTS

1 2 3

4 5 6

Page 15: About HTTP and REST

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

Page 16: About HTTP and REST

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.

Page 17: About HTTP and REST

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

Page 18: About HTTP and REST

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.

Page 19: About HTTP and REST

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.)

Page 20: About HTTP and REST

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

Page 21: About HTTP and REST

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

Page 22: About HTTP and REST

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.

Page 23: About HTTP and REST

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

Page 24: About HTTP and REST

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.

Page 25: About HTTP and REST

Code on Demand6REST allows client functionality to be extended by downloading and executing code in the form of scripts.

Page 26: About HTTP and REST

TESTINGRESTful APIs (with forms)

Page 27: About HTTP and REST

Simple REST Client is a plugin for Chrome. Once installed, you should have a button in the toolbar.

Download Simple REST Client

Page 28: About HTTP and REST
Page 29: About HTTP and REST

• The API POST URL• A POST string• Content Type header

What else do you need?

Page 30: About HTTP and REST
Page 31: About HTTP and REST

THE END.