rest
play

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


  1. REST CS 4720 – Mobile Application Development CS 4720

  2. And verily the Intarwebz were created • The evolution of the web – Server / Client – Simple pages – Web applications CS 4720 2

  3. And verily the Intarwebz were created CS 4720 3

  4. And verily the Intarwebz were created CS 4720 4

  5. And verily the Intarwebz were created CS 4720 5

  6. The Statefulness… or lack there of… • How does state play into SIS? • Why? How? CS 4720 6

  7. 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! CS 4720 7

  8. REST • Definition: REST – Representation State Transfer – a software architectural style for distributed hypermedia systems, such as the web – (but not necessarily the web) CS 4720 8

  9. 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 CS 4720 9

  10. 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 CS 4720 10

  11. 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 CS 4720 11

  12. 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 CS 4720 12

  13. Principles of REST • 5. Formatted/Structured Data • The resources you get should be encoded in a uniform way (like HTML, XML, etc.) CS 4720 13

  14. 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? CS 4720 14

  15. RESTful Shopping • What are the actions that you want to take in a shopping application? CS 4720 15

  16. 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 CS 4720 16

  17. 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 CS 4720 17

  18. RESTful Shopping 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? CS 4720 18

  19. 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 CS 4720 19

  20. 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 CS 4720 20

  21. Describing the World • We generally refer to client/server systems as “two-tier systems” • Why? • What does that communicate? CS 4720 21

  22. 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? CS 4720 22

  23. Context Clues • It’s all in what you’re talking about. • If you’re discussion the overall system, including the client, a common view of a three-tier architecture might be this: CS 4720 23

  24. 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 CS 4720 24

  25. 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 CS 4720 25

  26. 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 CS 4720 26

  27. 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) CS 4720 27

  28. MVC CS 4720 28

  29. MVC CS 4720 29

  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 of both • In general, a good MVC system will be RESTful, although a RESTful system does not have to follow MVC. CS 4720 30

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend