Skip to content

Instantly share code, notes, and snippets.

@Delta456
Created October 11, 2023 17:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Delta456/7eb63308a79d333a67a3d369a2b726f8 to your computer and use it in GitHub Desktop.
Save Delta456/7eb63308a79d333a67a3d369a2b726f8 to your computer and use it in GitHub Desktop.
HTTP Networking Notes

HTTP

HTTP stands for Hyper Text Protocol

It is one of the most powerful protocol. HTTP is not the only protocol uses URLs.

Protocol

Protocol is a set of rules, and two computers can follow this instructions. It also tells how to parse this information as something useful.

It is also referred as scheme. Some examples of URL protocols:

  • https
  • http
  • ftp
  • mailto

Not all schemes require "//" as it is only included for authority component.

Requests and Responses

The client is known as the requesting computer which asks another computer for some information.

Meanwhile the server is known as the computer which sends the info back to the client that it requested.


Prefix in URLs are used to tell which request to use


fetch JavaScript

const response = await fetch(url, settings)
const responseData = await response.json()
  • url is the URL of request
  • settings contains config in as an object

await is needed to pause the code, and wait for that response to come back as we are sending bits of data, sometimes almost across the world.

IP Address

IPv4: Address separated by periods, and each section is in the range of 0-255. Four numbers, each number is one byte of information. Every device connected to the internet has its own unique IP address. Eg: 8.13.156.7

IPv6: Newer format, way more possible than IPv4 because running out of IPv4 address, separated by colon and has six sections

In order to connect to a server, its unique IP address needs to be known.

DNS

Map human readable to IP addresses. Computers first resolve the DNS before connecting.

For example, in the URL https://github.com/vlang has a hostname of github.com, and rest ain't part of the DNS mapping.

URIs

It is a unique character sequence that identifies a resource that can be accessed via the internet.

It comes in two types:

  • URLs (locator)
  • URNs (name)

Note: URLs are only one kind of URI.

Sections of URL

http://testuser:testpass@testdomain.com:8080/testpath?testsearch=testvalue#testhash

protocol: http:
username: testuser
password: testpass
hostname: testdomain.com
port: 8080
pathname: /testpath
search: ?testsearch=testvalue
hash: #testhash

hash is used to link a section of a website and search is a map

HTTP Headers

An HTTP header allows clients and servers to pass additional information with each request or response. They are always case-insensitive key-value pairs that pass additional metadata about the request or response

where metadata is what headers are typically used for, is like data for data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment