Upgrade to Pro — share decks privately, control downloads, hide ads and more …

HTTP Overview

HTTP Overview

Some important basic information about HTTP Protocol.

Quỳnh Nguyễn

February 20, 2019
Tweet

Other Decks in Technology

Transcript

  1. Introduction Full name: Nguyễn Xuân Quỳnh Birthday: 07/11/1995 - Gender:

    Male Job: Software Developer Slogan - “The only way to be better is working harder.” 2
  2. Social Networks You can find me at: • https://www.linkedin.com/in/seriquynh •

    https://github.com/seriquynh • https://twitter.com/seriquynh 3
  3. Table of Content • Computer Network • Network Topology •

    Client-Server Architecture • Network Protocol • HTTP Protocol • Handling an HTTP Request 4
  4. Computer Network Computer Network is a set of computers and

    electronic devices such as printers, scanners that are connected via cables or wireless radio wave. In which, a device is called a node and all nodes can exchange data with each others. 6
  5. Client-Server Architecture Client-Server Architecture (client/server) is a network architecture in

    which each computer or device on the network is either a client or a server. 13
  6. Client-Server Architecture A Server is a computer that can store

    and share resources for all clients connects to it. A Client is a computer or device (such as a personal computer) that can access resources from the server. 14
  7. Network Protocol Network Protocol is set of rules in which

    all nodes have to follow to connect with each others. 17
  8. Network Protocol • Transmission Control Protocol (TCP) • Internet Protocol(IP)

    • Hypertext Transfer Protocol (HTTP) • File Transfer Protocol (FTP) • Secured Shell (SSH) • Simple Mail Transfer Protocol (SMTP) • Domain Name System (DNS) • Post Office Protocol version 3 (POP 3) • ... 18
  9. HTTP Protocol - Request Message GET /example HTTP/1.1 Host: localhost:8080

    Accept: text/plain, text/html [Message Body] First Line: - GET - is the method. - /example - is the path info and query string. - HTTP/1.1 - is the protocol version Next lines: - The listing of header fields. - A header field is a pair name: value. Finally: - The request body is optional. 20
  10. HTTP Protocol - Response Message HTTP/1.1 200 OK Date: Sat,

    09 Oct 2010 14:28:02 GMT Server: Apache Accept-Ranges: bytes Content-Length: 29769 Content-Type: text/html <!DOCTYPE html... (here comes the 29769 bytes of the requested web page) First Line: - HTTP/1.1 - is the protocol version. - 200 is the status code. - OK is the status text. Next lines: - The listing of header fields. - A header field is a pair name: value. Finally: - The response body. 21
  11. HTTP Protocol - Components • Method • Path and Query

    String • Version • Header • Status (code, text) • Message Body 22
  12. HTTP Protocol - Method Method Description GET The GET method

    requests a representation of the specified resource. Requests using GET should only retrieve data. HEAD The HEAD method asks for a response identical to that of a GET request, but without the response body. 23
  13. HTTP Protocol - Method Method Description POST The POST method

    is used to submit an entity to the specified resource, often causing a change in state or side effects on the server. PUT The PUT method replaces all current representations of the target resource with the request payload. DELETE The DELETE method deletes the specified resource. PATCH The PATCH method is used to apply partial modifications to a resource. 24
  14. HTTP Protocol - Path and Query String A Uniform Resource

    Identifier (URI) is a string of characters that unambiguously identifies a particular resource. URI = scheme:[//authority]path[?query][#fragment] authority = [userinfo@]host[:port] 25
  15. HTTP Protocol - Path and Query String • http://localhost/ •

    http://localhost/example • http://localhost/example?name=qqq • http://localhost/example?name=qqq#a-fragment • http://localhost/example?name=qqq&age=24 26
  16. HTTP Protocol - Header General header Headers applying to both

    requests and responses but with no relation to the data eventually transmitted in the body. Request Header Headers containing more information about the resource to be fetched or about the client itself. Response Header Headers with additional information about the response, like its location or about the server itself (name and version etc.). Entity Header Headers containing more information about the body of the entity, like its content length or its MIME-type. 28
  17. HTTP Protocol - Status (Code) 29 Status Code Description 1xx

    (Informational): The request was received, continuing process 2xx (Successful): The request was successfully received, understood, and accepted 3xx (Redirection): Further action needs to be taken in order to complete the request 4xx (Client Error): The request contains bad syntax or cannot be fulfilled 5xx (Server Error): The server failed to fulfill an apparently valid request
  18. HTTP Protocol - Status (Text) 30 Status Text Description 200

    OK 401 Unauthorized 403 Forbidden 404 Not Found 405 Method Not Allowed 500 Internal Server Error
  19. HTTP Protocol - Message Body Both request and response can

    contain a message body. • Request Body can be a payload of the submitted form. • Response Body will be read and display by the client. 31
  20. HTTP Protocol - Flow 1. The client opens a connection

    to the server. 2. The client sends an HTTP request the server. 3. The server handles the incoming HTTP request and returns an HTTP response. 4. The client receives and reads the HTTP response. 5. The client closes or reuses the opening connection for the other requests. 32
  21. HTTP Protocol - Extensible New functionality can even be introduced

    by a simple agreement between a client and a server about a new header's semantics. 35
  22. HTTP Protocol - Stateless, but not sessionless HTTP is stateless

    but HTTP cookies allow the use of stateful sessions. 36
  23. Handling an HTTP Request 1. Start a nodejs server. 2.

    Send an HTTP Request via Browser, CURL and HTTPie. 3. Return an HTTP Response. a. Interact with Status. b. Interact with Content-Type. c. Interact with customized headers. 38