HTTP
Hypertext Transfer Protocol
-
Resumo/Informações
HTTP - Hypertext Transfer Protocol
- Identifying Resources on the Web Based on the Request/Response protocol.
- URN: Uniform Resource Name   * Uniquely identifies resourse or name of resource.
- URI: Uniform Resource Identifier   * Uniquely identifies resource or location of resource.
- URL: Uniform Resource Locator  * Form of URI that provides info on how to get resource.
- Request Stucture GET:
- Response Stucture HTTP/1.1 - HTTP Version
- Examples: Response Status Codes - STATUS * 200 OK - OK, here is the content you requested. :)
1) Cliente abre uma conexão com o servidor.
2) Cliente envia HTTP request sobre um recurso.
3) O servidor envia uma resposta HTTP para o cliente (com o recurso).
4) O cliente fecha a conexão com o servidor.
5) Caso o recurso não é encontrado um erro ocorre.
  * Does not tell us how to get the resourse.
  Ex: HTML/CSS/javascript/Web Developers/Yaakov/Chaikin seria um link único utilizado pelo Coursera para identificar esse curso dentro do site.
  * Does not necessarily tell us how to get the resource.
  Ex: /official_web_site/index.html - this url alone doesn't say where you can find this.
 Ex: http://mysite.co.uk/index.html
 * URN & URI: uniforms a resource identification, but does not provides its location.
 * URL: provides a identification that directly sends you to the location of the resource.
  Resumo:
  1. Client connects with the server of mysite.co.uk.
  2. The HTTP gets in action, being the comunication language between the client and server.
HTTP Methods
  * Retrieves the resource.
  * Data is passed to server as part of the URI. Passa a data para o server como parte da URL.
Ex: GET / index.html?firstName=Diego HTTP/1.1
Get: method
index.html: URI String
?firstName=Diego: Query String (name/value pairs separeted by & examble: ?first=Diego&last=M.)
HTTP/1.1: HTTP Version
POST:
  * Sends data to server to be processed.
  * Data is sent in the message body. Envia dados como parte da mensagem no body.
Ex: POST / index.html HTTP/1.1
Host: coursera.org       \ Request
Accept-Charset: utf-8 / Headers
firstName=Diego...      - Message body starts here
...
200 - Response status code
OK - English phrase describing status code
Content-Type: text/html
HTML content here - Aqui pode ser jSon, entre outros.
...
...
* 404 NOT FOUND - Server can't find the resource requested.
* 403 FORBIDDEN - Unauthenticated client tried to access a secure resource.
* 500 INTERNAL SERVER ERROR - Some unhandled error was raised on the server.
Onreadystatechange: allows an event to happen at every state change. Permite disparar um evento a cada mudança de status (abaixo).
readyState - STATES
0 - UNSENT - Object not initiated, open() method still wasn't called.
1 - OPENED - Loading data, send() method still wasn't called.
2 - HEADERS_RECEIVED - Data loaded, send() method still wasn't called but the head responses were recieved.
3 - LOADING - Modo interativo, the response is being recieved.
4 - DONE - Operation completed. What was requested already got it's answer