Unit 1: HTTP, Application Architecture, Ruby and Rails

Jan 20, 2011

Objectives

Gain a strong understanding of HTTP and the general architecture of Web applications and how they work.

Get to know Ruby and understand how the Rails framework fits into the architecture of a Web application.

Recap / Prerequisites

After completing Unit 1 you should have a good idea of how web application development has reached its current state of the art. With Project 1.1, you should have a better understanding of how client-side markup and technologies (HTML, CSS, JS) provide you the ability to create a user interface's elements, visual layout, and behavior. You should have a good understanding of how not to create a Web application, and understand some best practices regarding "semantic markup."

HTTP

What makes the Web the Web? It all starts with HTTP. It's critical for the best Web application developers to have a strong understanding of how this simple protocol works and how every Web application, regardless of platform or framework, uses the protocol. Understanding HTTP is especially valuable when troubleshooting your applications.

To understand HTTP, briefly read this introduction to HTTP 1.1 (by the way, you should definitely know what the W3C is!) and focus on the "terminology" and "overall operation" sections. Next, read this approachable overview to HTTP. Read all of those sections quickly but pay attention to headers, status codes and methods (realize there are more than just GET and POST, but we'll get to that later when we discuss REST), and skip the last section on AJAX. Lastly, watch the short screencast I've created that discusses GET vs. POST and shows you how you can watch the HTTP requests sent by the browser and the responses sent by the server.

Architecture

Next, it's certainly expected of every developer to have a strong understanding of the common "3-tier" Web application architecture. It all comes down to this:

Most Web applications follow this exact architecture. However, the reason why I've stressed learning about the history of Web apps (Unit 1), understanding HTTP and this general architecture is because you should be asking yourself, "Is there a better way to build network applications over the Web?" or "Geez, you mean every server response sends the entire user interface back to the browser for rendering?" The landscape of Web applications is changing and there is room for experimentation with new ideas, designs and architectures. For example, consider Comet. You don't have to master this idea, but you should be able to understand how it works and why it might be used. Or consider that many AJAX frameworks prefer JSON to XML over the wire. Why?

Ruby, Rails, and MVC

Although this class is really about Web applications in general, every top-notch developer should strive to master his or her preferred language, platform and framework. Ultimately, these days we strive to become empowered "DevOps" which means mastering all of the dependencies of Web applications such as the Linux OS, Apache, TCP/IP networks, and MySQL/Postgres. You can certainly substitute the Microsoft stack. However, these ideas are outside the scope of this class.

We are, however, going to strive to become better Ruby programmers and Rails developers, as doing so is going to help exercise your ability to learn a new language and how to efficiently learn an API. Because both Ruby and Rails follow certain conventions, there are certain expectations upon the developer to follow "the Way." Don't feel like this is programming fascism; I think you'll find that this principal actually empowers you to be more productive, write less code and program at higher levels of abstraction.

There are numerous tutorials on Ruby, and you should start with Appendix A of Agile Web Development with Rails . However, the best way to learn a new language is to create something with it; hence, an excellent way to learn Ruby is to work with Rails. Don't worry if Ruby's syntax (such as blocks and yields) is confusing, it will become second nature soon. For now, watch the short screencast that provides you with a basic introduction to the Ruby ecosystem. If you fall in love with Ruby (you know I love to play matchmaker), I feel the best book these days is The Ruby Programming Language by Matz himself, from O'Reilly.

Lastly, you should have a strong understanding of the Model-View-Controller design pattern. There are actually slightly different flavors (implementations) of MVC in different contexts, but in the context of Web applications most MVC-based Web frameworks are very similar. Here's a decent high-level diagram about Rails and MVC:

You should also read the first section of this article (ignore everything past "SuperModels") and pay attention to the story mentioned at the end of the screencast.

No due date for the above readings, but you will be tested on HTTP and architecture.