Week 9 - Networking and APIs

Introduction to Networking

Client Server Model

TCP/IP Protocol

HTTP Protocol

URL Format

Web APIs

API Testing Tools

Using APIs

Practice

Assignment

Core program

The TCP/IP Protocol

The TCP/IP Protocol (Transmission Control Protocol/Internet Protocol) is the fundamental set of rules that governs virtually all communication over the internet, making it the main protocol.

TCP/IP defines how electronic devices should connect to the Internet and how data should be transmitted between them. It ensures that data sent from one device (like a web server) is correctly received by another (like a user's browser), regardless of the network technology or operating system used by either device.

<aside> πŸ’‘

The HTTP protocol that we will discuss in the next chapter uses the TCP/IP protocol under the hood to transfer requests and responses between clients (e.g., browsers) and servers.

</aside>

Message Packaging and Transmission

When you access a website, the information you request, whether it's an image, a large HTML file or video, is broken down and sent across the network as small, manageable chunks called packets.

  1. TCP: Breaking it Down
  2. IP: Addressing and Sending

Once all the packets arrive at the destination, TCP uses the sequence numbers to put them back in the correct order, reassembling the original, complete file or message for the web browser to display.

The IP Address

An IP Address is a unique numerical label assigned to every device (computer, server, smartphone) connected to a computer network that uses the Internet Protocol for communication. It acts as the address for your device on the internet. Its main job is to identify a device and its location so that data packets can be routed correctly across the network.

The Domain Name System (DNS)

The Domain Name System (DNS) is a global, distributed directory service. It translates human-readable Domain Names (like google.com) into the numerical IP Addresses (like 142.251.36.46) that computers need to find each other.

Since humans remember names better than long strings of numbers, DNS acts as the Internet's phone book.

When you type a web address into your browser:

  1. Your browser asks a DNS Server (the "phone book") for the IP address corresponding to the domain name.
  2. The DNS server finds the correct IP address.
  3. Your browser then uses that IP address to connect directly to the web server.

This step is critical for web development because a web server's IP address might change (e.g., if you switch hosting providers), but the domain name remains the same, thanks to DNS updates.

The ping Command

The ping command tests basic connectivity and measures round-trip time (latency) to a destination host (IP address or domain name). It repeatedly sends β€œping” messages to the specified address (either a numerical IP address or a DNS name) and shows statistics about the replies from the destination address. It includes the numeric IP address of the responder, if any. Example:

> ping google.com

PING google.com (142.250.179.174): 56 data bytes
64 bytes from 142.250.179.174: icmp_seq=0 ttl=120 time=14.732 ms
64 bytes from 142.250.179.174: icmp_seq=1 ttl=120 time=12.148 ms
64 bytes from 142.250.179.174: icmp_seq=2 ttl=120 time=12.247 ms
64 bytes from 142.250.179.174: icmp_seq=3 ttl=120 time=7.617 ms
64 bytes from 142.250.179.174: icmp_seq=4 ttl=120 time=8.698 ms
^C

Press Ctrl-C to stop the ping command.

In this example, the IP address of the DNS name google.com is 142.250.179.174.

<aside> ⌨️

Try it yourself!

The nslookup Command

Another way to quickly look up the IP address, given a domain name, is by using the nslookup command. In this case, the name is resolved by querying the Domain Name System (DNS) servers.

> nslookup google.com

Server:		192.168.178.1
Address:	192.168.178.1#53

Non-authoritative answer:
Name:	google.com
Address: 142.250.179.174

The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0 **

CC BY-NC-SA 4.0 Icons

*https://hackyourfuture.net/*