I am finishing up the first course of Tealeaf Academy. It’s an awesome online bootcamp, which I’ll go into more detail about in a later post. My new goal is to post about what I learn so I can better retain it. This post goes over the basics of HTTP requests and model-view-controller, two concepts which are vital for understanding back-end development. I would hear these terms thrown around, and didn’t really understand them until the last two units of this course.
HTTP requests are what make the internet go round. When you enter a URL, the DNS (Domain Naming System) maps that URL to an IP address in order to locate the website. This complicated process is explained by this adorable webcomic, if you want more details. The “http://” at the beginning of URLs stands for “Hypertext Transfer Protocol”. HTTP requests are issued by the client (your browser) and receive responses from a server. HTTP requests are typically GET or POST requests. GET is getting data from a server, as the name suggests. POST is posting or sending data to server, and is used often by forms.
The server sends back an HTTP response which contains:
- Headers- contain information about the server.
- Status Code – indicates the status of the response. Common codes include 200 (OK), 404 (Not Found), 500 (Internal server Error), and 302 (Redirect).
- Message Body- seen in POST requests, this is raw response data, such as the HTML.
An important note about HTTP requests is they are stateless. An HTTP request knows nothing about any request that came before it. This means developers must use certain tactics to make an application look state-ful. To allow websites such as Facebook and Reddit to store your information, and keep you logged in, a HTTP request contains a session ID, or unique token. The is why browsers store cookies. Clients compare cookies with the server’s session data. POST requests can contain parameters that can also be saved into the session data.
One consequence of HTTP requests is that they refresh the entire browser. To avoid this, websites can use AJAX, or Asynchronous Javascript and XML. This way the entire page does not have to reload when you like something on Facebook. Using AJAX, the URL stays the same, as the HTTP requests operate behind the scenes.
Many web applications operate under the Model-View-Controller model. In such an application:
1. The browser issues a request.
2. The controller either redirects (issues a new request) or renders a view.
3. The views are your HTML and CSS files. In Ruby, we can render HTML using templates such as ERB or HAML.
4. The model works with the controller, and concerns information such as the session ID or database information.
All this knowledge culminated in a blackjack web application. Can’t wait to learn about Ruby on Rails and databases in the next course.