Web Development Basics
Learning Objectives
- Define web development and distinguish between frontend and backend.
- Explain the Client-Server architecture and the HTTP request/response cycle.
- Identify the core frontend technologies (HTML, CSS, JavaScript) and their roles.
- Understand the Document Object Model (DOM) and how JavaScript interacts with it.
- Define REST APIs and standard HTTP methods (GET, POST, PUT, DELETE) and basic status codes.
- Understand fundamental web authentication methods (Sessions/Cookies vs. Tokens/JWT).
- Recognize common web security vulnerabilities such as XSS and CSRF.
An introduction to building websites and applications, covering the Client-Server architecture, HTML/CSS/JavaScript, the DOM, REST APIs, and Authentication.
Web Development
Web Development is the process of building, creating, and maintaining websites and web applications that run online within a browser. It is generally divided into two main areas: Frontend (what the user sees and interacts with) and Backend (the server, database, and logic that powers the application behind the scenes).
HTTP
HTTP (Hypertext Transfer Protocol) is the foundation of data communication for the World Wide Web. It functions as a request-response protocol in the client-server computing model.
API
An API (Application Programming Interface) is a set of rules and protocols that allows different software applications to communicate with each other. In web development, APIs usually refer to web services that expose data and functionality over HTTP.
1. The Client-Server Architecture
The internet operates on a fundamental model where a Client (your web browser, like Chrome or Safari, running on your laptop or phone) requests information or services from a Server (a powerful, remote computer that stores the website's files, databases, and logic).
1. The Request: The user types a URL (e.g.,
www.example.com). The browser (Client) first asks a DNS server to translate that URL into an IP address. It then sends an HTTP Request across the internet to the specific Server located at that IP address.2. The Processing: The Server receives the HTTP request, processes any necessary backend logic (like querying a database for the user's profile data), and prepares the response.
3. The Response: The Server sends back an HTTP Response to the Client. This response contains a status code (like
200 OKor404 Not Found) and the payload (the HTML, CSS, JavaScript, or JSON data needed).4. The Rendering: The Client's browser receives the payload, parses the code, and visually renders the website on the screen.
2. Frontend Development (The Client Side)
Frontend development focuses on everything the user directly interacts with in their browser. It is built using three core technologies: HTML, CSS, and JavaScript.
2.1 HTML (HyperText Markup Language)
HTML provides the Structure or skeleton of the webpage. It uses "tags" to define semantic elements like headings (<h1>), paragraphs (<p>), links (<a>), and images (<img>).
2.2 CSS (Cascading Style Sheets) CSS provides the Styling or visual presentation. It controls layout, colors, typography, spacing, and responsive design (using Media Queries to make the site look good on both small mobile phones and large desktop monitors).
2.3 JavaScript (JS) JavaScript provides the Interactivity and logic. It allows the page to respond to user actions (like clicking a button, validating a form, or fetching new data) dynamically, without needing to reload the entire page from the server.
DOM (Document Object Model)
The DOM is an application programming interface for web documents. It represents the page so that programs can change the document structure, style, and content. The DOM represents the document as nodes and objects (a tree structure).
DOM Manipulation Example
When a browser loads an HTML document, it creates the DOM in memory. JavaScript can find an element using document.getElementById("alertBox"), modify its text content to show an error message, and change its background color to red when a user types an invalid password, all by manipulating the DOM tree.
Interact with the simulation below to toggle the different frontend layers (HTML, CSS, JS) and see how they build upon each other.
Web Layers
Welcome
Clicks: 0
3. Backend Development (The Server Side)
Backend development involves the server hardware, the database, and the application logic that powers the website behind the scenes, ensuring data is processed securely and efficiently.
Server Environment / Framework: Software running on the server that listens for incoming HTTP requests and routes them to the correct logic. Examples include Node.js (Express), Python (Django/Flask), Java (Spring Boot), PHP (Laravel), or Ruby on Rails.
Database: Systems used to permanently store application state, user accounts, products, posts, etc. Can be Relational (PostgreSQL, MySQL) or Non-Relational (MongoDB).
Application Logic (Business Rules): The custom code that acts as the bridge between the database and the frontend, processing calculations, verifying passwords, and enforcing security checks before sending data back.
3.1 REST APIs (Representational State Transfer)
A REST API is a standard architectural style for designing networked applications. It provides a structured way for the Frontend (Client) to communicate with the Backend (Server) using standard HTTP methods to manipulate data. Modern web apps (Single Page Applications like React or Angular) and mobile apps rely heavily on REST APIs. Data is almost universally transmitted in JSON (JavaScript Object Notation) format.
Standard HTTP Methods (CRUD Mapping):
- GET (Read): Retrieve data from the server (e.g., getting a list of products). GET requests should never modify data.
- POST (Create): Send new data to the server to create a new resource (e.g., submitting a user registration form).
- PUT / PATCH (Update): Modify existing data on the server (e.g., updating a user's shipping address).
- DELETE (Delete): Remove a specific resource from the server.
3.2 HTTP Status Codes
Every HTTP response from a server includes a status code to indicate the result of the request.
- 2xx (Success): The request was successfully received, understood, and accepted. (e.g.,
200 OK,201 Created). - 3xx (Redirection): Further action needs to be taken in order to complete the request. (e.g.,
301 Moved Permanently). - 4xx (Client Error): The request contains bad syntax or cannot be fulfilled due to a client error. (e.g.,
400 Bad Request,401 Unauthorized,404 Not Found). - 5xx (Server Error): The server failed to fulfill a valid request. (e.g.,
500 Internal Server Error).
4. Authentication and Security Basics
Web applications must securely verify who a user is (Authentication) and what specific actions they are allowed to perform (Authorization).
Authentication Mechanisms:
Session/Cookies (Stateful): The traditional method. The user logs in, and the server creates a "session" record in its memory. It then sends a small text file (a Cookie containing a Session ID) to the user's browser. The browser automatically sends this cookie back with every future request, proving the user is logged in.
Tokens / JWT (Stateless): A modern method commonly used with REST APIs. The user logs in, and the server generates an encrypted JSON Web Token (JWT). For subsequent requests, the client manually attaches this Token. The server does not need to remember sessions in memory; it simply verifies the signature.
OAuth / SSO (Single Sign-On): A protocol allowing users to grant a third-party application access to their information without sharing their password (e.g., "Login with Google").
Common Web Vulnerabilities
Security is critical. Common vulnerabilities include XSS (Cross-Site Scripting), where an attacker injects malicious JavaScript into a site that executes in other users' browsers, and CSRF (Cross-Site Request Forgery), where a malicious site tricks a user's browser into performing an unwanted action on a trusted site where they are authenticated.
- Web development relies fundamentally on the Client-Server model, where browsers request data and servers process and respond.
- The Client handles the visual rendering (Frontend), while the Server handles logic, databases, and security (Backend).
- HTML structures the content, CSS styles the visual presentation, and JavaScript adds dynamic interactivity.
- The DOM (Document Object Model) is the browser's internal tree representation of the HTML, which JavaScript manipulates to update the page visually without full reloads.
- The Backend consists of the server runtime, the database, and the business logic connecting them.
- REST APIs utilize standard HTTP methods (GET, POST, PUT, DELETE) to implement CRUD operations over the network.
- JSON is the standard format used to transmit structured data between the client and server.
- Authentication verifies identity (who you are), while Authorization determines access rights (what you can do).
- Modern REST APIs often use stateless Tokens (like JWTs) instead of traditional server-side Sessions for authentication.
- Web security involves protecting against common attacks like XSS (malicious script injection) and CSRF (unwanted authenticated actions).