REST CS 4720 Mobile Application Development CS 4720 And verily - - PowerPoint PPT Presentation

rest
SMART_READER_LITE
LIVE PREVIEW

REST CS 4720 Mobile Application Development CS 4720 And verily - - PowerPoint PPT Presentation

REST CS 4720 Mobile Application Development CS 4720 And verily the Intarwebz were created The evolution of the web Server / Client Simple pages Web applications CS 4720 2 And verily the Intarwebz were created CS 4720


slide-1
SLIDE 1

CS 4720

REST

CS 4720 – Mobile Application Development

slide-2
SLIDE 2

CS 4720

And verily the Intarwebz were created

  • The evolution of the web

– Server / Client – Simple pages – Web applications

2

slide-3
SLIDE 3

CS 4720

And verily the Intarwebz were created

3

slide-4
SLIDE 4

CS 4720

And verily the Intarwebz were created

4

slide-5
SLIDE 5

CS 4720

And verily the Intarwebz were created

5

slide-6
SLIDE 6

CS 4720

The Statefulness… or lack there of…

  • How does state play into SIS?
  • Why? How?

6

slide-7
SLIDE 7

CS 4720

Nouns speak louder than… verbs…

  • Look at the links in SIS
  • What are they? Verbs.
  • This is the “evolution” of the web

– We have tried to force the web into the same mold as stand-alone programs – This is not good! – We need to take advantage of the asynchronous nature of web communication!

7

slide-8
SLIDE 8

CS 4720

REST

  • Definition: REST

– Representation State Transfer – a software architectural style for distributed hypermedia systems, such as the web – (but not necessarily the web)

8

slide-9
SLIDE 9

CS 4720

Principles of REST

  • 1. Statelessness
  • In the simplest terms, this principle forbids for

any state information to be stored on the server

  • This does not forbid state to be stored client-

side

  • Every message though must contain all

information needed for understanding

9

slide-10
SLIDE 10

CS 4720

Principles of REST

  • 2. Idempotency
  • The output of identical requests is itself

identical

  • In other words, if you go to the same page

twice, you get the same page (barring changes in the content model)

  • Allows for caching, which improves user-

perceived responsiveness

10

slide-11
SLIDE 11

CS 4720

Principles of REST

  • 3. Addressable Resources
  • Everything has its place and every place has a

thing

  • “Everything is a resource”
  • See amazon.com for a good example
  • URLs reflect the resource

11

slide-12
SLIDE 12

CS 4720

Principles of REST

  • 4. Well-defined operations
  • In the context of the Web and HTTP, we’re

talking:

– POST – GET – PUT – DELETE

  • This reflects possible actions

12

slide-13
SLIDE 13

CS 4720

Principles of REST

  • 5. Formatted/Structured Data
  • The resources you get should be encoded in a

uniform way (like HTML, XML, etc.)

13

slide-14
SLIDE 14

CS 4720

Sounds good… but…

  • Sure sounds hard to pull off good web apps

with these constraints…

  • Let’s think about a shopping application
  • What’s the “usual” way?

14

slide-15
SLIDE 15

CS 4720

RESTful Shopping

  • What are the actions that you want to take in a

shopping application?

15

slide-16
SLIDE 16

CS 4720

RESTful Shopping

  • In real life, who holds the shopping cart?
  • You, or your personal shopping buddy

provided by the store?

  • If it’s you (and I hope it is) where do you store

cart information?

– In a frame? (UGH… I just threw up a little in my mouth) – In a cookie? (not what it’s meant for!) – HTML5 SessionStorage object J… eventually

16

slide-17
SLIDE 17

CS 4720

RESTful Shopping

  • Well, just for argument, we’ll give you your

shopping buddy (we’ll call him “Carl”)

  • In this instance, the shopper will be asking the

store to set aside items for them

  • The difference here is basically philosophical,

but bear with me

  • If we treat the cart as part of the STORE and

not owned by the CLIENT, then RESTfulness can still be maintained

17

slide-18
SLIDE 18

CS 4720

RESTful Shopping

18

Sender Message Client Show me your products. Server Here’s a list of products. Client Okay, I’d like to buy 2 of http://shop.com/product/X, place it in my basket, my username is “XtremeShopper” and password is “bubba” Server

  • Done. I’ve put it in your basket at

http://shop.com/users/XtremeShopper/basket Client Actually, I don’t need 1 of those. Please remove one of X from my basket, my username is “XtremeShopper” and password is “bubba” Server

  • Done. I’ve removed it from your basket at

http://shop.com/users/XtremeShopper/basket Client

  • Great. Ring it up - username is “XtremeShopper” password is “bubba”

Server Should I charge that to your account?

slide-19
SLIDE 19

CS 4720

RESTful Shopping

  • Uh… wasn’t that a session?
  • Not quite – a session disappears when the user

does

– Theoretically, this would be around until the user removes everything or checks out

  • It is addressable, it’s formatted, it’s

idempotent, and it uses defined operations

  • The differences are very subtle, but they are

there

19

slide-20
SLIDE 20

CS 4720

Sounds good… but…

  • REST means that the server is stateless and

cannot store any data about the client’s current state/session

  • This example was a bit extreme
  • Like most things, moderation is the key to

getting the right balance between server and client resource utilization

20

slide-21
SLIDE 21

CS 4720

Describing the World

  • We generally refer to client/server systems as

“two-tier systems”

  • Why?
  • What does that communicate?

21

slide-22
SLIDE 22

CS 4720

A Three-Tier System

  • How might a three-tier

system be different than a two tier?

  • Do we add a server?
  • Do we add a client?
  • What does it mean to have

three tiers?

22

slide-23
SLIDE 23

CS 4720

Context Clues

  • It’s all in what you’re talking about.
  • If you’re discussion the
  • verall system, including

the client, a common view of a three-tier architecture might be this:

23

slide-24
SLIDE 24

CS 4720

Principles of REST

  • Remember this one?

– 3. Addressable Resources – Everything has its place and every place has a thing – “Everything is a resource”

  • This is actually key to how we go about

building a three-tier web application

24

slide-25
SLIDE 25

CS 4720

RESTful Tiers

  • If every resource is a place, and every place is a

resource, how do we define our resources?

  • We know the URL would look something like:

– http://mysite.com/users/mss2x

  • Where:

– mysite.com is the domain – users is the “category of resources” – mss2x is a specific instance of the resource

25

slide-26
SLIDE 26

CS 4720

RESTful Tiers

  • What we want the web server / web

application to do is translate this:

– http://mysite.com/users/mss2x

  • Into effectively a function call that

– Identifies what the user is asking for – Loads a particular resource – Displays the pertinent info about that resource back to the user

26

slide-27
SLIDE 27

CS 4720

Model-View-Controller

  • This is the definition of what MVC is
  • The MVC pattern maps:

– Identifies what the user is asking for – Loads a particular resource – Displays the pertinent info about that resource back to the user

  • To Model, Controller, View (in that order)

27

slide-28
SLIDE 28

CS 4720

MVC

28

slide-29
SLIDE 29

CS 4720

MVC

29

slide-30
SLIDE 30

CS 4720

30

REST and MVC

  • REST and MVC aren’t directly related, but they

intersect in many, many ways

  • The idea of “nouns” in the system – of

addressable resources – is a major component

  • f both
  • In general, a good MVC system will be RESTful,

although a RESTful system does not have to follow MVC.