Double click to toggle Read Mode.

Web Application Programming

Github Link

Bidur Sapkota Bidur Sapkota

Web Application Programming by Bidur Sapkota

Table of Contents

  1. Introduction
  2. 1.2 Client-Server Architecture, HTTP, HTTPS, URLs, DNS, web browsers
  3. JavaScript and Client-Side Programming

Introduction

1.1 Overview of Web Applications and Evolution of Web Architecture

World Wide Web (WWW)

World Wide Web (WWW), commonly known as the Web, is an information system enabling information to be shared over the Internet through simplified ways meant to appeal to users beyond IT specialists and hobbyists, as well as documents and other web resources to be accessed over the Internet according to specific rules, the Hypertext Transfer Protocol (HTTP).

What are Web Applications?

Key Characteristics:

Evolution of Web or Rise of the World Wide Web

Web 1.0 (1990s - Early 2000s) - Static Web

Web 2.0 (Mid 2000s - 2010s) - Dynamic & Social Web

Web 3.0 (2010s - Present) - Semantic & Intelligent Web

Modern Web Applications - Current Trends


Evolution of Web Architecture

Summary Table

Evolution FactorPast / TraditionalTransitionalModern / Cutting Edge
GenerationWeb 1.0 (Read)Web 2.0 (Social)Web 3.0 (Decentralized, AI)
ArchitectureMonolithicMicroservicesEvent-Driven, Serverless

The Request/Response Procedure

Basic Request/Response Procedure

At its most basic level, the request/response process consists of a web browser or other client asking the web server to send it a web page and the server sending back the page. The browser then takes care of displaying or rendering the page.

Basic Request/Response Procedure

The steps in the request and response sequence are as follows:

  1. You enter http://server.com into your browser’s address bar.
  2. Your browser looks up the Internet Protocol (IP) address for server.com.
  3. Your browser issues a request for the home page at server.com.
  4. The request crosses the internet and arrives at the server.com web server.
  5. The web server, having received the request, looks for the web page on its disk.
  6. The web server retrieves the page and returns it to the browser.
  7. Your browser displays the web page.

For an average web page, this process also takes place once for each object within the page: a graphic, an embedded video or Flash file, and even a CSS template.

Dynamic Request/Response Procedure

Dynamic web pages work by using PHP to request data from a MySQL database based on what you click. MySQL sends back the needed information, and PHP turns it into HTML, which your browser displays.

Basic Request/Response Procedure

The steps are as follows:

  1. You enter http://server.com into your browser’s address bar.
  2. Your browser looks up the IP address for server.com.
  3. Your browser issues a request to that address for the web server’s home page.
  4. The request crosses the internet and arrives at the server.com web server.
  5. The web server, having received the request, fetches the home page from its hard disk.
  6. With the home page now in memory, the web server notices that it is a file incor‐ porating PHP scripting and passes the page to the PHP interpreter.
  7. The PHP interpreter executes the PHP code.
  8. Some of the PHP contains SQL statements, which the PHP interpreter now passes to the MySQL database engine.
  9. The MySQL database returns the results of the statements to the PHP interpreter.
  10. The PHP interpreter returns the results of the executed PHP code, along with the results from the MySQL database, to the web server.
  11. The web server returns the page to the requesting client, which displays it.
1.2 Client-Server Architecture, HTTP, HTTPS, URLs, DNS, web browsers

Client-server architecture is a distributed computing model where tasks are divided between service providers (servers) and service requesters (clients).

Components:

Client (Frontend):

Server (Backend):

Client-server architectures can be categorized into different tiers:

Single-tier Architecture(Monolithic Architecture):

Monolithic Client-Server Architecture

Two-tier Architecture:

Two-tier Client-Server Architecture

Multi-tier Architecture:

Three-tier Client-Server Architecture

Advantages of Client-Server Architecture

Disadvantages of Client-Server Architecture


HTTP (HyperText Transfer Protocol)

What is HTTP?

Key Features

HTTP Request

HTTP Request HTTP Request

1. Request Line: An HTTP request starts with a request line, which includes the following:

2. Request Headers: Following the request line are headers, which provide additional information about the request. This can include details about the client’s browser, the types of responses that the client will accept, cookies, and more.

3. Blank Line: A blank line indicates the end of the headers section.

4. Request Body (Optional): Not all requests have a body. Bodies are typically included in POST or PUT requests, where you’re sending data to the server (like form inputs or file uploads). The body contains the data being sent.

HTTP Response

An HTTP response is what a server sends back to the client after receiving and processing an HTTP request. Here’s a breakdown of the components of an HTTP response:

1. Status Line: This is the first line of the response and includes:

2. Response Headers: These are key-value pairs providing additional information about the response. They can include details such as the server type, content type, content length, caching policies, set cookies, and other metadata.

3. Blank Line: A blank line signifies the end of the header section.

4. Response Body: This part of the response contains the actual data or resource that the client requested. For example, it could be an HTML file, JSON data, an image, etc. In some cases, particularly when the response indicates an error (like a 404), the body might contain a message explaining the error.

HTTP Response

HTTP Response

HTTP Methods (Verbs)

MethodPurposeDescription
GETRetrieve dataRequests data from server, read-only
POSTSubmit dataSends data to server, creates resources
PUTUpdate dataUpdates existing resource completely
PATCHPartial updateUpdates part of existing resource
DELETERemove dataDeletes specified resource
HEADGet headersLike GET but only retrieves headers
OPTIONSGet optionsDescribes communication options

Head:

HTTP Status Codes

1xx - Informational:

2xx - Success:

3xx - Redirection:

4xx - Client Errors:

5xx - Server Errors:


HTTPS (HTTP Secure)

What is HTTPS?

HTTPS is the secure version of HTTP, using encryption to protect data transmission between client and server.

Key Features

Benefits


URLs (Uniform Resource Locators)

Structure of a URL

https://www.example.com:443/path/to/myfile.html?key1=val1&key2=val2#SomewhereInTheDocument Protocol: https:// Subdomain: www Domain: example Top-level domain (TLD): .com Port: :443 Path: /path/to/myfile.html Query String: ?key1=val1&key2=val2 Fragment: #SomewhereInTheDocument

Components Explained

Protocol (Scheme):

Domain Name:

Port:

Path:

Query String:

Fragment (Hash):

URL Encoding

Special characters must be encoded:


DNS (Domain Name System)

What is DNS?

DNS is the internet's phone book, translating human-readable domain names into IP addresses that computers use to communicate.

How DNS Works

  1. User enters URL: www.example.com in browser
  2. Browser checks cache: Looks for recently resolved IP
  3. Recursive resolver: ISP's DNS server receives request
  4. Root nameserver: Directs to TLD nameserver (.com)
  5. TLD nameserver: Directs to authoritative nameserver
  6. Authoritative nameserver: Returns IP address
  7. Browser connects: Uses IP to reach website

DNS Record Types

TypePurposeExample
AMaps domain to IPv4 addressexample.com → 192.0.2.1
AAAAMaps domain to IPv6 addressexample.com → 2001:0db8::1
CNAMEAlias to another domainwww → example.com
MXTells the internet which mail server receives email for your domain.Mail server for email
TXTStore text-based information for verification, email security, ownership, and configurations.SPF, DKIM, Domain verification records
NSNameserver recordsDefine Authoritative DNS servers

SPF (Sender Policy Framework)

DKIM (DomainKeys Identified Mail)

Domain verification


DNS Hierarchy

Root (.) └── Top-Level Domain (.com, .org, .net) └── Second-Level Domain (example.com) └── Subdomain (www.example.com)

.com.np is also at TLD level, Country Code TLD i.e. ccTLD


DNS Caching


Search Engines

What is a Search Engine?

A search engine is a software system designed to carry out web searches. They search the World Wide Web in a systematic way for particular information specified in a textual web search query.

How Search Engines Work

  1. Crawling:
  1. Indexing:
  1. Ranking:

Popular Search Engines


Web Browsers

What is a Web Browser?

A web browser is a software application that retrieves, presents, and navigates information resources on the World Wide Web.

Popular Browsers

Browser Components

1. User Interface:

2. Browser Engine:

3. Rendering Engine:

4. Networking:

5. JavaScript Engine:

6. Data Storage:

How Browsers Render Pages

Browser Features

Developer Tools:

Security Features:

Modern Capabilities:


JavaScript and Client-Side Programming