Before sessions and cookies: HTTP request and response
Tags: flatiron, rails, sessions, cookies
Published: 2021-08-13 03:04:55





###INTRO
Rails authentication is all about sessions and cookies. But before that I needed little refresh on HTTP requests and responses. It all sounded familiar but I wanted to have it all in one place as a reference when (not if) I need it.
___
##Finding HTTP requests/responses
It's always good to see what are we talking about. Please see instructions hot to see HTTP requests/responses for Chrome browser:
  *Navigate to page (anyone you like)
  *Right click and hit 'Inspect'
  *Select 'Network'
  *Select any HTTP request on left side (panel named 'name') and headers will be displayed on right side 
___


##HTTP(Hypertext Transfer Protocol) request

HTTP request is a message that one computer sends to another using the HTTP protocol. It’s made by a client of ours API to our API. 


####Structure:

**1. The Request line** of the HTTP protocol (has three parts):
Example 1. *GET /books HTTP/1.1*
Example 2. *POST /form.html HTTP/1.1*

**1.1 HTTP Method**- indicate what kind of action our client wants to perform
*GET*- user wants to “read” a resource (example 1.)
*POST*- user wants to send us something (example 2.)

**1.2 URI of request**- refers to the address where the resource is located
Example 1. The user wants to “read”(GET) resources located at */books*
Example 2. The user wants to send(POST) something (form.html), we will find this in the body of the HTTP request 

**1.3 HTTP protocol**- there are several versions of HTTP (example *HTTP/1.1*)

**2. The headers of the HTTP request** are metadata that are sent in requests to provide information about the request.
Each header is specified with a name, then two points, and then followed by the value of that header. The header can be composed of several individual headers.

**metadata** in HTTP request- when we retrieve page the server sends with it various bits of information about the thing you are retrieving (metadata).
**metadata in general**- data that provide information about other data. Metadata summarizes basic information about data, making finding and working with particular instances of data easier.

**3. The body of HTTP request** place where we put additional information we want is going to send to the server. We can put whatever we want in the body of the request. The body represents (in many cases) content that we want to transmit.
GET requests do not use a body since it’s not sending many complex data when reading information. In the case of the POST method, we use the body of the request to send data to the server (sign in forms for example).
___
##HTTP Response
####Structure: 

**1. Status line**
The request status is indicated in the response status line. If there are errors, if it was successful or if it is required some additional actions.
[Read more about HTTP status code.](
https://en.wikipedia.org/wiki/List_of_HTTP_status_codes)

**2. The response header**
Is set of one or many headers (just like in HTTP request)

**3. The body of the response**
This part is optional, used when the server wants to transmit data to the user (for a web page it would be HTML (hypertext markup language)  document)


sources: 
[HTTP headers, meta elements and language information](https://www.w3.org/International/questions/qa-http-and-lang)
[Anatomy of an HTTP request] (https://gavilan.blog/2019/01/03/anatomy-of-an-http-request/)
[about metadata] (https://www.opendatasoft.com/blog/2016/08/25/what-is-metadata-and-why-is-it-important-data)
[how to see HTTP headers](https://mkyong.com/computer-tips/how-to-view-http-headers-in-google-chrome/)