You are on page 1of 15

📝

Network requests article


Status Done

Network Requests: A Comprehensive


Guide for JS Developers (and not only)

The topics of the article:

1. Introduction

2. What is a Protocol ?

3. Open Systems Interconnection (OSI) Model

4. TCP/IP model: TCP/IP vs OSI

5. Well known protocols explained

6. HTTP/HTTPS

7. AJAX, XMLHttpRequest vs Fetch API

Network requests article 1


When trying to understand how the communication between client and server works,
terms like “protocols”, “OSI”, “HTTP”, “synchronous/asynchronous web
communication”, “TCP/IP” and many more are impossible to avoid.

To understand the “how”, let’s first find out what network requests are and what the
above mentioned terms actually mean.

The first term to understand is “network protocol”.

Protocols
As MDN states: “A protocol is a system of rules that define how data is exchanged
within or between computers.”

So a network protocol is an established set of rules that define the transmission,


formatting and receiving of data between different devices. Two different computers
within a network can have totally different infrastructures, underlying designs,
internal processes and standards. The role of a network protocol is to make it
possible for such devises to communicate data.

A well-known analogy is two people from different countries not speaking each
other’s native language and therefore using a third common language to
communicate.

There are many protocols for different process types. It is easier to categorize them
by defining what OSI level they can be found in.

So the next term to understand is the OSI.

Open Systems Interconnection (OSI) Model

Network requests article 2


To put it simple OSI is an abstract representation of how internet works.

It does not perform any function in the networking process but describes 7 layers
that the communication between two devices goes through.

What each layer does is described in the image below:

Network requests article 3


But let’s describe each layer in simpler terms.

1. Physical Layer
Is the lowest layer of the OSI model. What it is concerned with is transmitting data
from the physical layer of the sending device to the physical layer of the receiving
device either electronically or optically. It is all about the actual physical resources
that take part in the data communication process, i.e. cabling, network adapters,
modems, network hubs, etc. Therefore it can have voltage, radio frequency, cabling
specifications. Data at this layer is unstructured.

This layer has several major functions:

Defining physical specifications

Defining protocols

Defining transmission mode (half duplex & full duplex)

Defining the network’s topology

So the physical layer is responsible for the physical cable or wireless connection

Network requests article 4


between network nodes. It defines the connector, the electrical cable or wireless
technology connecting the devices, and is responsible for transmission of the raw
data, which is simply a series of 0s and 1s, while taking care of bit rate control.

2. DataLink Layer
It’s also a lower layer where the node-to-node data transfer occurs. The DataLink
layer is where switches operate and it provides a reliable link between two directly
connected nodes to transfer the data
.
This layer is responsible for the following operations:

Packaging data into frames

Performing node-to-node data transfer

Correcting errors that may have occurred at the Physical layer

The DataLink layer is divided into 2 separate layers

The Media Access Control (MAC) layer


Is responsible controlling how devices connected to the network gain access.

Logical Link Control (LLC) layer


Controls error checking, possible fixes and packet synchronization. Is also the
layer that identifies the protocols.

3. Network Layer
At the Network layer, the focus expands from a point-to-point link to include many
interconnected nodes within a network. Network layer devices operate on packets
and are responsible for routing traffic to its destination based on IP addresses. At
this layer, routers are a crucial component used to quite literally route information
where it needs to go between networks. The router is responsible for sending
packets of information out into the internet and receiving them. These packets origin
and destination is determined by the IP address of your router.

Network requests article 5


Note: A packet is a very small segment of a large message. The data
transferred between machines is split into packets by the sending machine
and then is collected and recombined by the receiving one.

4. Transport Layer
The Transport layer is basically responsible for the logistics of the session.
It has the following functionalities:

Manages the delivery and error checking of data packets

Regulates the size of data

Ensures that data arrives in the correct sequence

Regulates the transfer of data between systems and hosts

Makes sure errors are corrected

5. Session Layer
The Session layer has the task of creating and maintaining sessions between the
operating system on the presentation layer and other, third party machines.

Session layer services include

Setup

Network requests article 6


Authentication

Termination

Re-connection.

6. Presentation Layer
Plainly said the core responsibility of the Presentation layer us to translate data from
network data to the formats expected by an application. This is the layer where the
Operating System(OS) can be found.
Data encodings and encryption are managed at this layer.

7. Application Layer
The Application layer is where the user inputs data and data is output to the user. It
is a software run the local machine, but not always, since it depends on the network
architecture. The software could run off a server in a remote location and data would
be transferred over the internet, this is the case of the cloud based software.

The Physical, DataLink, Network, Transport layers are considered lower layers and
the Session, Presentation, Application are higher levels.

Network requests article 7


When a user is browsing the internet, they are interacting with the application layer,
the application layer is interacting with the presentation layer and the session layer
allows the operating system to interact with the web server and then the data is
taken to the lower layers.

Below is an illustration depicting the designated responsibilities of each layer in a


simple way with additional information.

Network requests article 8


The OSI 7-layer model is widely used, as it helps visualize and communicate how
networks operate, and helps isolate and troubleshoot networking problems.
However the modern Internet is not based on OSI, but on the simpler TCP/IP model,
which will be discussed next.

TCP/IP model: TCP/IP vs OSI


TCP stands for Transmission Control Protocal and IP stands for Internet Protocol.

TCP/IP model predates the OSI model and is more concentrated on the
implementation of networking stacks.

Network requests article 9


The TCP/IP model contains the following layers:

1. Network Access Layer: Ethernet, Token Ring, ATM, and Frame Relay are
examples from the TCP/IP Protocol Suite that operate at this layer.

2. Internet Layer: This layer is primarily covered by the Internet Protocol (IP), but
ARP, IGMP, and ICMP also operate at this layer.

3. Transport Layer: TCP and the User Datagram Protocol (UDP) operate at this
layer.

4. Application Layer: Some protocols that operate at this layer include HTTP,
SMTP, and DNS.

The OSI model is more theoretical, describing the various tasks that must be
accomplished to enable application-layer data to be transmitted via electricity, light,
or radio waves. The TCP/IP model is more practical and maps closely to actual
network protocols. It is a customer server model that is used for data information
transmission. It is a communication protocols suite using which network devices can
be connected to the Internet.

Characteristics of the OSI Model

Network requests article 10


Here are some important characteristics of the OSI model:

A layer should only be created where the definite levels of abstraction are
needed.

The function of each layer should be selected as per the internationally


standardized protocols.

The number of layers should be large so that separate functions should not be
put in the same layer. At the same time, it should be small enough so that
architecture doesn’t become very complicated.

In the OSI model, each layer relies on the next lower layer to perform primitive
functions. Every level should able to provide services to the next higher layer.

Changes made in one layer should not need changes in other laYers.

Characteristics TCP/IP Model


Here are the essential characteristics of the TCP/IP protocol:

Support for a flexible architecture

Adding more systems to a network is easy.

In TCP/IP, the network remains intact until the source and destination machines
were functioning properly.

TCP is a connection-oriented protocol.

TCP offers reliability and ensures that data which arrives out of sequence should
put back into order.

TCP allows you to implement flow control, so the sender never overpowers a
receiver with data.

Now we can move on to understanding what particular protocols do.

Well Known Protocols Explained


Transmission Control Protocol (TCP): TCP is a popular communication
protocol which is used for communicating over a network. It divides any
message into series of packets that are sent from source to destination and
there it gets reassembled at the destination.

Internet Protocol (IP): IP is designed explicitly as addressing protocol. It is


mostly used with TCP. The IP addresses in packets help in routing them through

Network requests article 11


different nodes in a network until it reaches the destination system. TCP/IP is the
most popular protocol connecting the networks.

User Datagram Protocol (UDP): UDP is a substitute communication protocol to


Transmission Control Protocol implemented primarily for creating loss-tolerating
and low-latency linking between different applications.

Post office Protocol (POP): POP3 is designed for receiving incoming E-mails.
Simple mail transport Protocol (SMTP): SMTP is designed to send and distribute
outgoing E-Mail.

File Transfer Protocol (FTP): FTP allows users to transfer files from one
machine to another. Types of files may include program files, multimedia files,
text files, and documents, etc.

Hyper Text Transfer Protocol (HTTP): The purpose of HTTP is to


communicate hypertext between two or more systems. Links are made using
HTML tags. These connections could be text links or picture links. According to
client-server design principles, HTTP enables a client system to connect to the
server device in order to submit a request. The server acknowledges the client's
request and reacts appropriately.

Hyper Text Transfer Protocol Secure (HTTPS): Hyper Text Transfer Protocol
Secure, also known as HTTPS, is a common protocol to protect communication
between two computers, one of which is using a browser and the other is
retrieving data from a web server. The client browser (request) and web server
(response) both utilize HTTP to send data between them in a hypertext manner;
HTTPS is similar to HTTP, with the exception that the data transmission takes
place in an encrypted format. So it may be claimed that https prevents hackers
from interpreting or changing data while packets are being transferred.

We will concentrate more on the HTTP/HTTPS protocols since as JS developers


they are the ones we usually deal with.

HTTP/HTTPS
HTTP

Network requests article 12


In essence, HTTP serves as a secure communication protocol over the Internet to
uphold the veracity, accuracy, and secrecy of the user's personal data that would
otherwise be utilized inappropriately. The HTTP and HTTPS protocols are the two
main forms of HTTP that are used on the Internet. Since HTTPS stands for
Hypertext Transfer Protocol Secure, it is the more secure form of the protocol in this
case. Due to its inability to protect user data confidentiality and ease of hacking by
attackers for the purpose of obtaining user data, regular HTTP is far less secure than
the highest-end HTTPS.
The main distinction between the HTTP and HTTPS protocols is that the latter uses
TLS (Transport Layer Security) in addition to SSL (Secure Sockets Layer),
increasing the security and confidentiality of user data. Additionally, the additional
certifications, such as TLS and SSL, are not guaranteed by the basic HTTP protocol.
The Uniform Resource Locator (URL) for the HTTP protocol begins with http://, while
the corresponding URI for the HTTPS protocol begins with https://.
The lock icon that appears on the URL tab, which indicates that the specific website
is fully protected and the user may also make payments through the website with a
credit card, is the most noticeable distinction between an HTTP and an HTTPS
website while using the web browser. However, a website using the HTTP protocol
will not display the lock icon and will instead warn users to leave the site and refrain
from entering their passwords or credit card numbers because there is no data
confidentiality and a high risk of data leakage, which would allow hackers to obtain
all of the user's personal and financial information.

HTTPS

Network requests article 13


The Secure Hypertext Transfer Protocol (HTTPS), also known as an Internet
standard protocol, is used on the Internet to encrypt and protect the secrecy of the
regular HTTP protocol. It is in charge of applying various high-security cryptographic
methods to user data to prevent data theft and leakage of sensitive information,
including passwords and other financial data pertaining to credit cards and debit
cards. With the use of the TLS and SSL layer certifications, HTTPS enables the web
browser to identify and flag websites that have an additional layer of security. To
guarantee confidentiality and authentication in communication, it provides an
additional layer of encryption. Additionally, it increases the stability and security of
protection against unknown servers and websites. Because TLS (Transport Layer
Security) controls all data transfer procedures between two computers, websites that
use the HTTPS protocol may be trusted with ease. HTTPS is crucial in preventing
and reminding people to stay away from websites that have tampering and data-
stealing problems and are more frequently targeted by hackers. In order to prevent
anyone from tracking the data packets used to target users with targeted adverts
and SQL Injection attacks, it applies a VPN to the device's local area network.
Using the Transport Layer Security protocol, the HTTPS provides three layers of
security and encryption to the data transmission, further enhancing its security.

Network requests article 14


These are what they are:

Data on websites that use HTTPS cannot be changed since it meets the
requirements for data integrity.

It encrypts data in order to monitor all attackers who aim to access someone's
account and then steal their personal information.

The data authentication in HTTPS demonstrates its dependability and protects


users from websites like denial-of-service attacks and middle-man attacks that
steal users' data.

Network requests article 15

You might also like