DEV Community

Ayush Dutta
Ayush Dutta

Posted on

Web-Apps: Networks-based deep dive

What's HTTP?

HTTP (Hypertext Transfer Protocol) is designed to interconnect nodes containing hypertext, which are documents that can embed text and multimedia. The global interconnection of these nodes forms the internet.

Building an Alternative to HTTP

HTTP has been the backbone of web communication for decades. However, evolving web technologies demand innovation. Let's explore the key components of HTTP and consider possible alternatives.

Understanding HTTP and Hypertext

Hypertext is the foundation of the World Wide Web. Browsers interpret it using HTML (Hypertext Markup Language). When a browser requests a webpage, it sends an HTTP request to a web server, which responds with an HTML document and other resources.

Client-Server Architecture

HTTP uses a client-server model:

  • The client (typically a browser) sends requests for resources.
  • The server processes requests and sends back responses.

Rethinking Client-Server Architecture

Alternatives to HTTP could focus on:

  • Persistent Connections: Keeping connections open for faster communication.
  • Streaming Data: Supporting continuous, real-time data streaming.
  • Bidirectional Communication: Allowing real-time, two-way messaging.

Security in Web Protocols

HTTPS (Hypertext Transfer Protocol Secure) encrypts data transfers between client and server. It uses TLS (Transport Layer Security) to ensure:

  • Data Integrity: Preventing data alteration.
  • Confidentiality: Encrypting data for intended recipients only.
  • Authentication: Verifying identities to prevent impersonation attacks.

You're absolutely right, and I apologize for that oversight. Let me add a section on APIs and the request-response model:

APIs and the Request-Response Model

What Are APIs?

Application Programming Interfaces (APIs) are crucial in modern web applications. They define rules for how different software systems communicate, enabling seamless integration between various applications and services.

Key Aspects of APIs:

  1. Standardization: APIs standardize communication between different applications.
  2. Functionality: They allow retrieval of data, execution of operations, and more.
  3. Versatility: APIs power web applications, mobile apps, IoT devices, and more.

The Request-Response Model

Most APIs, including those based on HTTP, use the client-server request-response model:

  1. Request: The client sends a request to the server for a specific resource or action.
  2. Processing: The server processes the request.
  3. Response: The server sends back a response, which may include data, status information, or both.

Example of API Request-Response:

Request:
GET /api/users/123 HTTP/1.1
Host: api.example.com

Response:
HTTP/1.1 200 OK
Content-Type: application/json

{
  "id": 123,
  "name": "John Doe",
  "email": "john@example.com"
}
Enter fullscreen mode Exit fullscreen mode

HTTP Methods Guide

GET

GET /api/users/123 HTTP/1.1
Host: api.example.com
Enter fullscreen mode Exit fullscreen mode
  • Used to retrieve resources
  • Should not modify server state
  • Data is sent in query parameters
  • Idempotent and cacheable

POST

POST /api/users HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
  "name": "John Doe",
  "email": "john@example.com"
}
Enter fullscreen mode Exit fullscreen mode
  • Used to create new resources
  • Can modify server state
  • Data is sent in the request body
  • Not idempotent, but can be made cacheable

PUT

PUT /api/users/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
  "name": "John Smith",
  "email": "john.smith@example.com"
}
Enter fullscreen mode Exit fullscreen mode
  • Used to update existing resources
  • Replaces the entire resource
  • Idempotent but not cacheable

PATCH

PATCH /api/users/123 HTTP/1.1
Host: api.example.com
Content-Type: application/json

{
  "email": "john.smith@example.com"
}
Enter fullscreen mode Exit fullscreen mode
  • Used for partial updates to resources
  • Only specified fields are updated
  • Not guaranteed to be idempotent

DELETE

DELETE /api/users/123 HTTP/1.1
Host: api.example.com
Enter fullscreen mode Exit fullscreen mode
  • Used to delete resources
  • Idempotent but not cacheable

These methods form the core of RESTful API design, each serving a specific purpose in resource manipulation. The choice of method depends on the operation you want to perform on the resource.

Common API Architectures:

  1. RESTful APIs: Use HTTP methods (GET, POST, PUT, DELETE) to perform operations on resources.
  2. GraphQL: Allows clients to request specific data structures, reducing over-fetching.
  3. WebSocket APIs: Enable real-time, bidirectional communication.

Understanding DNS and Domain Names

The Domain Name System (DNS) translates human-readable domain names into IP addresses. This process involves:

  1. Browser cache check
  2. Query to DNS resolver
  3. Resolver queries DNS servers
  4. Resolution returns the response

Domain Name Hierarchy

Domain names have a hierarchical structure:

  • Top-Level Domain (TLD): e.g., .com, .org
  • Second-Level Domain (2LD): e.g., example in example.com
  • Third-Level Domain (3LD) or Subdomain: e.g., www in www.example.com

DNS Resolution Process

  1. User enters URL
  2. Local cache lookup
  3. Query sent to DNS resolver
  4. Root DNS server queried
  5. TLD DNS server queried
  6. Authoritative DNS server queried
  7. IP address returned to browser

Ports in System Processes

Ports are logical constructs that identify specific processes or services in network communication. They allow computers to direct network traffic to the correct applications.

Types of Ports

  1. Well-Known Ports (0-1023): Used by system processes and main network services.
  2. Registered Ports (1024-49151): Used by applications not part of core services.
  3. Dynamic or Private Ports (49152-65535): Used for temporary connections.

Security Concerns for Ports

  • Close unused ports
  • Use firewalls to control port access
  • Conduct regular port scans

Cloud Machines

Cloud machines are virtual computing instances provided by cloud service providers like AWS, Google Cloud, or Azure. They offer scalability, on-demand availability, and remote access.

Benefits of Cloud Machines

  • Scalability
  • Pay-as-you-go pricing
  • OS flexibility
  • Managed infrastructure

Containers

Containers are lightweight, portable units that package an application and its dependencies. They share the host OS kernel, making them more resource-efficient than VMs.

Advantages of Containers

  • Lightweight
  • Portable
  • Fast deployment
  • Consistent environments

Containers vs. Virtual Machines (VMs)

Characteristic Containers Virtual Machines
Architecture Share host OS kernel Each has its own OS
Startup Time Fast (seconds) Slow (minutes)
Resource Usage Low High
Isolation Process-level Full OS-level
Portability Highly portable Less portable

Deploying a Web App to AWS EC2 and Mapping a Domain

Step 1: Create an AWS EC2 Instance

  1. Log in to AWS Management Console
  2. Launch a new EC2 instance:
    • Choose an AMI and instance type
    • Configure security group (allow HTTP, SSH, and your app's port)
    • Launch and download SSH key

Step 2: Deploy the Web Application

  1. SSH into your EC2 instance
  2. Install required software
  3. Upload your web app
  4. Run your application

Step 3: Set Up a Domain Name and Map it to EC2 IP

  1. Buy a domain name
  2. Create an A record pointing to your EC2 instance's public IP
  3. Set TTL to a low value (e.g., 300 seconds)

Step 4: Access the Web App via the Domain

Wait for DNS propagation, then access your app using the domain name.

Step 5: Share the Website Link

Once everything is set up, share your website link (e.g., https://www.example.com).

Top comments (0)