DEV Community

Carrie
Carrie

Posted on

What are OSI Model and HTTP Request for Beginners

If you are a completely novice in the web application area, you are at the right place. This is a beginner's guide to understand the OSI Model and HTTP request.

The OSI (Open Systems Interconnection) model

The OSI (Open Systems Interconnection) model is a conceptual framework used to understand and standardize the functions of a telecommunication or computing system without regard to its underlying internal structure and technology.

It is organized into seven layers, each specifying particular network functions.

Image description

source: https://blog.nashtechglobal.com/open-systems-interconnection-osi-model/

1.Physical Layer (Layer 1)

Purpose: Deals with the physical connection between devices.

Functions:

  • Transmits raw binary data over physical mediums like cables, radio frequencies, or fiber optics.
  • Defines hardware components like cables, switches, and network interface cards.
  • Manages data encoding, signaling, and bit synchronization.

Example Components: Ethernet cables, Hubs, Repeaters.

2.Data Link Layer (Layer 2)

Purpose: Ensures reliable transmission of data across a physical network.

Functions:

  • Packages raw data from the physical layer into frames.
  • Handles error detection and correction from physical transmission errors.
  • Manages MAC (Media Access Control) addresses which identify devices on a local network.

Example Components: Switches, Bridges.

3.Network Layer (Layer 3)

Purpose: Manages device addressing and determines the best path to send data.

Functions:

  • Routes data packets between different networks.
  • Uses logical addresses like IP addresses to identify devices.
  • Determines the optimal path for data delivery.

Example Components: Routers, IP Protocol.

4.Transport Layer (Layer 4)

Purpose: Ensures complete data transfer.

Functions:

  • Segments data from the sending host and reassembles it on the receiving host.
  • Provides error detection and recovery.
  • Manages flow control to prevent network congestion.
  • Uses protocols like TCP (Transmission Control Protocol) for reliable delivery and UDP (User Datagram Protocol) for faster, connectionless delivery.

Example Components: TCP, UDP.

5.Session Layer (Layer 5)

Purpose: Manages sessions between applications.

Functions:

  • Establishes, manages, and terminates connections between applications.
  • Handles session restoration and synchronization.

Example Components: Session protocols (e.g., NetBIOS, RPC).

6.Presentation Layer (Layer 6)

Purpose: Translates data between the application layer and the network.

Functions:

  • Converts data formats so that applications can understand data coming from different network formats.
  • Handles data encryption and decryption for secure transmission.
  • Manages data compression to reduce the size of the data.

Example Components: SSL/TLS, JPEG, MPEG.

7.Application Layer (Layer 7)

Purpose: Closest to the end user; it interacts with software applications.

Functions:

  • Provides network services directly to end-users.
  • Facilitates activities like file transfers, email, and other network software services.
  • Interfaces with application software to implement communication functions.

Example Components: HTTP, FTP, SMTP, DNS.

Key Points to Remember

Each layer has a specific function and communicates with the layers directly above and below it.

Data encapsulation: As data passes down the layers from the application to the physical layer, each layer adds its own header (and sometimes footer) information.

Interoperability: The OSI model helps different systems and networks communicate with each other, ensuring interoperability and standardization.

How the OSI Model Works in Practice

When you send an email, it passes through each layer of the OSI model:

  1. Application Layer: Your email client (e.g., Gmail) formats the email.
  2. Presentation Layer: The email is encrypted.
  3. Session Layer: The session is established between your device and the email server.
  4. Transport Layer: The email is broken into segments, each given a sequence number.
  5. Network Layer: The segments are packaged into packets with source and destination IP addresses.
  6. Data Link Layer: Packets are framed with MAC addresses.
  7. Physical Layer: The frames are converted into electrical, radio, or optical signals and transmitted over the physical medium.

The receiving device then reverses the process to reconstruct the email.

The OSI model is a fundamental concept in networking, providing a universal language for network communication. Understanding each layer helps diagnose network issues, design efficient networks, and ensure different systems can work together seamlessly.

What is an HTTP Request

An HTTP (HyperText Transfer Protocol) request is a message sent by a client (usually a web browser) to a server to request resources or perform actions on a web server. These requests are part of the protocol used by the World Wide Web, defining how messages are formatted and transmitted, and what actions web servers and browsers should take in response to various commands.

Components of an HTTP Request

1.Request Line
Method: Specifies the action to be performed. Common methods include:
- GET: Requests a representation of the specified resource. Requests using GET should only retrieve data.
- POST: Submits data to be processed to a specified resource.
- PUT: Uploads a representation of the specified resource.
- DELETE: Deletes the specified resource.
- HEAD: Similar to GET but without the response body.
- OPTIONS: Describes the communication options for the target resource.
- PATCH: Partially modifies the resource.
URI (Uniform Resource Identifier): Indicates the resource on the server
HTTP Version: Indicates the HTTP version being used (e.g., HTTP/1.1, HTTP/2).

Example:

   GET /index.html HTTP/1.1
Enter fullscreen mode Exit fullscreen mode

2.Headers
Provide metadata about the request. They are key-value pairs separated by a colon (:). Common headers include:
- Host: Specifies the domain name of the server (mandatory in HTTP/1.1).
- User-Agent: Contains information about the user agent (browser) making the request.
- Accept: Informs the server about the types of data that can be sent back.
- Content-Type: Indicates the media type of the body of the request (used with methods like POST and PUT).
- Authorization: Contains credentials for authenticating the client with the server.

Example:

   Host: www.example.com
   User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
   Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Enter fullscreen mode Exit fullscreen mode

3.Body
The body contains the data sent to the server (with methods like POST and PUT). It is optional and is used when the client needs to send data to the server.

Example (for a POST request):

   name=John&age=30
Enter fullscreen mode Exit fullscreen mode

Example of a Complete HTTP Request

Here's a full example of an HTTP GET request:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Enter fullscreen mode Exit fullscreen mode

Example of a Complete HTTP POST Request

Here's a full example of an HTTP POST request:

POST /form-submit HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 27
Connection: keep-alive

name=John&age=30
Enter fullscreen mode Exit fullscreen mode

In summary, an HTTP request is a structured message sent by the client to the server, containing a request line, headers, and an optional body, depending on the method used and the purpose of the request.

Top comments (2)

Collapse
 
saamiabbaskhan profile image
Saami abbas Khan

Bro, literally yesterday I had my Computer Networks exam, and all these questions came up.

Btw Great knowledge, keep it up!

Collapse
 
carrie_luo1 profile image
Carrie

I'm so glad to hear that! Thanks for your encouragement!