REST 101: Part 1 - Understanding Resources 23

We're starting a new series today.
For some reason, learning about REST was a bigger struggle for me than it ever needed to be. I'm not exactly sure what that was. Maybe it's because I spent so much of my life writing client applications, not web applications. Maybe it was because (read quickly now) I was getting up to speed on the whole HTTP programming thing at the same time I was learning Ruby at the same time I was learning Rails and it was right after that I went to the first RailsConf and everyone got excited about REST and I smiled like I understood so I wouldn't look like an idiot but really I had no idea what was going on... Whew.
If you're trying to make sense of what REST on Rails is all about, then this series is for you.
People who are experts in HTTP, HTML, and REST might nitpick with my simplified terminology so I can focus on the topic at hand. If that's you, I don't want to hear about it, because this series isn't for you anyway :-)
Square One
Let's begin at the beginning. How does a web browser work? Before trying to build websites with Rails, I used to think it was something like this:
- I type in a url into the address bar, or click on a link
- The browser makes an "http request" (whatever that means) and gets HTML code in response
- The browser renders the new HTML onto the page
And that was pretty much it. And I never really thought about how forms worked, either. I just figured they were a variant of the above.
In reality, the HTTP protocol includes exact instructions on how a browser should send its request to the server. HTTP is totally different from HTML, which happens to be the markup language chosen to represent the page content. It turns out that HTTP enables the browser to retrieve all kinds of information from the server, beyond simply getting an HTML page or submitting form data. In fact, HTTP actually allows for eight different kinds of requests to be made to the server. However, we are most familiar with these two kinds of requests:
- A "GET" request: get the contents of some resource on the web; the resource is uniquely identifed by a URL;
- A "POST" request: send a package of data to a URL to create a new resource.
Square Two
See how I've slipped in the word "resource" when you weren't expecting it? Well, this is where my first, critical turning-point in thinking came in trying to understand REST: thinking of the web as a collection of resources, not "web pages". What do I mean by that?
Yesterday, I went on amazon.com and looked at some products I could buy. I also read some articles on Wikipedia. I read some news headlines on CNN. Then I checked the latest NHL standings to see just exactly how far Chicago is out of the playoffs.
If you want to understand REST, you have to stop thinking of these things as web pages. Let's take a Wikipedia article as an example. It's not just a web page. It's a resource - in my case, a short biography of Archimedes. I happened to use a web browser to access that resource, so the web browser requested an HTML representation of that resource, because rendering HTML is only way web browsers can display resources.
I know this is weird at first. Isn't the Archimedes article a web page? No. I asked for the HTML representation for a resource held by Wikipedia, a resource that can be identified by the URI "//en.wikipedia.org/wiki/Archimedes". Wikipedia could have chosen to represent that resource in any number of ways - with a PDF, or perhaps as a .jpg picture. Maybe they offer all of those. But Firefox used a GET request that specified that the resource should be provided by the server as HTML, so that's what I got.
Another example: my plane reservation is a resource held by United Airlines. They let me get to that resource in many ways: as an HTML page, but they can also send my reservation information as a text message to my cell phone. Or they could send it to me in plain text in an email. Or I could call them up on this old device and they would tell it to me verbally. Same resource, multiple representations.
So I hope it's obvious now: my airline reservation is not just a web page. It's a real resource that (fortunately for me) can be rendered whenever I choose with HTML, and I can use my browser to request that representation and render it onto my screen.
Square Three
Ok, once you can accept that the web is actually a huge collection of resources that can be rendered in multiple ways, and that an HTML rendering is just one of those, then there's one more concept I want you to grasp before we stop today. Resources aren't just single things like biographical articles, or an airline reservation, or a sports statistic. Some resources are collections of other resources. A list of holidays can be a resource. A list of friends can be a resource. A series of blog posts can be a resource.
Now that you understand what resources are, tune in next time when we talk about how HTTP enables the creation, reading, updating, and destruction of resources. (Rats, I think I just gave it away.)
Questions? Suggestions? Flames? Leave a comment and tell me.




Thank you for this series! It looks like it's gonna be excellent reading. I'm really looking forward to it.
MCN
This is a very good introduction to resources. Looking forward to the next article in the series.
Thank you for writing this series. I am very interested in seeing the rest of the articles.
Thanks Jeff.
It's good to see a well explained high level post on REST like this. After DHH explained it in his speech a while back, there seemed to be a bit of confusion flying around. Now we have more experience it's good to take a step back to clarify things.
Looking forward to the next instalment.
For those that get all wobbly in the knees when talking about HTTP and other protocols with capital P's, it's worth playing with HTTP by hand, at least once. Try this:
telnet amazon.com 80 GET /
You should see lots of HTML scrolling by now. Now you know what it feels like to be Firefox.
Try other fun ones:
GET /robots.txt GET /favicon.ico
Not so scary any more, now is it?
Mephisto ate my line breaks! Let's try again...
telnet amazon.com 80
GET /
GET /robots.txt
GET /favicon.ico
(If this doesn't work, the telnet is one line and each GET request goes on its own line)
Thanks for this series. I'm also trying to wrap my mind around REST so I can update my Rails apps. I look forward to reading future articles.
John, the telnet example helped me a lot as well...
My only suggestion would be a "next" link to the next article :) Otherwise a really neat description of resources - will not hunt out the other articles.
Eep s/not/now !
Thanks so much for sharing your struggles to help the REST of us! I'm learning about REST and Rails and Ruby all at the same time and struggling with wrapping my head around REST. This series is perfect as it's all finally starting to sink in and reading your series is finally giving me the "aha" and "light bulbs" about REST.
nice man quite self explinatory.....
very nice introduction about resources. Thanks a lot sharing your experience.
Neat Article, Thanks!!!
tit big tit huge tit big tit round ass tiny tit tit fuck small tit tit and ass teen tit how big tit work big black tit cum tit perfect tit big tit patrol tit fucking nice tit black tit asian big tit big tit teen big natural tit sexy tit soft tit mature tit fat tit asian tit hot tit tit palace big tit movie saggy tit big tit and ass giant tit natural tit tit flash naked tit big tit porn tit and pussy little tit mature big tit big tit lesbian monster tit flashing tit bouncing tit nude tit rate my tit wife tit massive tit young tit large tit tit sucking lactating tit big tit fucking beach tit tit milk big tit video biggest tit big tit blonde great tit fake tit big tit pic beautiful tit ebony tit tit sex big tit sex old tit milf tit firm tit big tit fuck blonde tit round tit perky tit wet tit big tit bangers anime tit show tit tit job milking tit japanese tit big tit milf big tit blow job lesbian tit big tit hentai gigantic tit indian tit milky tit huge black tit hanging tit hentai tit no tit party tit real tit absolutly big free tit ebony big tit amateur tit suck tit tiny teen tit big tit gallery black lorded tit bbw tit mega tit amateur big tit tit big tit huge tit big tit round ass tiny tit tit fuck small tit tit and ass teen tit how big tit work big black tit cum tit perfect tit big tit patrol tit fucking nice tit black tit asian big tit big tit teen big natural tit sexy tit soft tit mature tit fat tit asian tit hot tit tit palace big tit movie saggy tit big tit and ass giant tit natural tit tit flash naked tit big tit porn tit and pussy little tit mature big tit big tit lesbian monster tit flashing tit bouncing tit nude tit rate my tit wife tit massive tit young tit large tit tit sucking lactating tit big tit fucking beach tit tit milk big tit video biggest tit big tit blonde great tit fake tit big tit pic beautiful tit ebony tit tit sex big tit sex old tit milf tit firm tit big tit fuck blonde tit round tit perky tit wet tit big tit bangers anime tit show tit tit job milking tit japanese tit big tit milf big tit blow job lesbian tit big tit hentai gigantic tit indian tit milky tit huge black tit hanging tit hentai tit no tit party tit real tit absolutly big free tit ebony big tit amateur tit suck tit tiny teen tit big tit gallery black lorded tit bbw tit mega tit amateur big tit
Thanks for the useful resource of information : )
Thanks, you have a good and easy way to teach things like that :)
Really very nice.
Thanks for being a great resource!
Hey, this article was really great, I have been having such a hard time finding an article to just explain the basics and applications of REST. Thanks!
This was nice :) I have having a hard time decoding other people’s “representations” of REST.. lol, thank you very much :D
I don’t usually leave comments but I have come up with your your 101 series and been reading them for an hour and the way you write is so easy and fun to read that it deserves a nice comment :)
nice article! great introduction. Fun to read ;) and … simple. Thanks!
Well, that’s the clearest description I have yet encountered.
Resources are like ore: they’re in a mine.
The Web is the smelter: it changes the ore into something valuable and visible.
The Browser shows me the refined result.
Hence, the resource could be anything: trees, gold nuggets, food, photos, sheesh!! Who knew?
Many thanks. On to the next segment with renewed optimism.
Ken
hey good intro to resources…keep up the good work….