RESTful rails and resources Flashcards
What is HTTP?
b-simple.de/download/restful_rails_en.pdf
Hypertext transfer protocol is the response and request rule system by which browsers communicate with servers to draw out the information browsers need to deliver images, sound, text, video to users. HTTP is the foundation of data transfer, without it the internet as a communication medium doesn’t exist.
HTTP runs on top of the TCP/IP protocols (which are the real foundational protocols of the internet).
What is an HTTP demon?
The correct term is daemon. An HTTP daemon is a program that exists in servers to lie in wait listening patiently for HTTP client requests (from your browser), and once these daemon programs get a request they can act on them and respond with the website pages and resources those servers have stored.
http://searchwindevelopment.techtarget.com/definition/HTTP
When you make a request to a server, such as requesting google dot come, a GET request and a POST request are made. Explain.
https://www.youtube.com/watch?v=X4aNa6W9hyE
A GET request is basically the code that encapsulates everything you need from the server. It starts with a request line and then has a number of header fields, a POST request is similar.
www.abc.com?v=xxxxname=bob is an example of a GET
The question mark is the GET, and everything to the right is called a query string. 99% of the time this is a bad idea since what we want to pass is visible, so 99% of the time we’ll use the POST method.
GET and POST are just two types of HTTP requests transmitted from browsers to servers.
What is GPPD (and REST)?
GET and POST requests transfer data from client to server.
PUT creates data.
DELETE destroys.
The GPPD options together are termed REST. Rails supports REST. A RESTful rails app then is quite popular. Scaffolding is a RESTful feature.
What is REST.
The term REST was coined by some guy ina PhD dissertation, it means Representational State Transfer. The Representational State transfer describes an architecture paradigm (fancier term for foundational model) for all web apps which utilize HTTP methods GPPD (get, post, put, delete) to request and manipulate reources.
WHat is a resource in regards to REST?
A REST resource is an entity that offers interaction via HTTP, and this resource is retrievable by way of a URL address.
Resources can be represented in HTML, XML, RSS, depending on what the client requests.
REST resource URLs are unique, while URLs in rails usually address models and its action, a resource URL only addresses the resource itself.
Note that in the context of an actual rails app the resource is a combination of a dedicated model and controller. In the picture attached we see our REST resource called project in action.
What does REST do for our rails development?
REST was not always a part of the Rails MVC structure, but REST comes with its perks:
Clean URLs. REST URLs represent actions and not actions.
Different response formats. REST controller actions can deliver their results in different formats liek HTML, XML, RSS , or other data formats. App controller can handle multi-client code.
Less Code. Because controllers can handle multi-client code helps us avoid repetitions and thereby causes less code.
CRUD-oriented Controllers. Controllers and resources melt into one unit, so each controller has its own resource to be responsible for.
Clear Application Design. RESTful rails apps are very clear and easy to maintain and understand.
REST is MVC based and it’s techniques can be boiled down to 4 factors. What are they?
* The usage of respond_to in controller code.
* New helper methods for links and forms.
* The usage of URL methods to controller redirects.
* New routes that are generated from the method resources in routes.rb
Once you understand these REST techniques designing RESTful apps will become a breeze.
The b-simple article after the first 12 pages requires more rails experience than I have, so I moved on to:
https://spring.io/understanding/REST
What is REST?
Representational state transfer or REST was developed in 2000 by some PhD guy for his dissertation. It is an architectural style for designing distributed systems, it is not a standard but rather a set of constraints, such as being:
* Stateless
* having a client/server relationship
* uniform interface
REST has 4 principles:
(1) Messages hold HTTP methods explicitly
(2) Resources expose easily understood directory structure URIs
(3) Representations transfer JSON or XML to represent data objects and attributes.
(4) Stateless interactions store no client context on the server between requests. State dependencies limit scalability. The client holds session state.