NET Centric Computing · Unit 8
Client-Side Technologies and Single Page Applications
Exam-focused notes for Client-Side Technologies and Single Page Applications (NET Centric Computing, BIT351): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Client-Side Technologies and Single Page Applications in short
Modern web apps often run most of their logic in the browser and talk to a server through APIs. This chapter covers single page applications, the React and Angular frameworks, REST and JSON.
What this unit covers
- Single Page Application significance
- SPA uses and benefits
- React framework fundamentals
- React form creation
- React email and phone validation
- Angular framework usage
- REST API integration
- JSON format and advantages
React form creation
2081 · 5 marks
Create a form using React with your own assumption. [5]
2081.1 · 5 marks
How do you create form using React? Illustrate with an example. [5]
Single Page Application significance
2080 · 10 marks
What re the signigicances of Single Page Application? How do you integrate REST API calls? Describe.[10]
Angular framework usage
JSON format and advantages
SPA uses and benefits
0 · 5 marks
What is the use of SPA? Elaborate. [5]
Show solved answerHide answer
Use of SPA (Single Page Application)
What is SPA?
A Single Page Application (SPA) is a web application that loads a single HTML page and dynamically updates the content as the user interacts with the app, without reloading the entire page from the server.
Examples: Gmail, Google Maps, Facebook, Twitter
Uses / Purposes of SPA
1. Fast and Responsive User Experience
- SPA loads the page only once; subsequent interactions update only the required portion of the page.
- This eliminates full page reloads, making the application feel fast and fluid like a desktop app.
2. Reduced Server Load
- Only data (JSON/XML) is exchanged between client and server after the initial load.
- The server does not need to render full HTML pages repeatedly, reducing bandwidth and server processing.
3. Better User Interaction
- SPA provides a seamless navigation experience.
- Users do not experience blank screens or flickering during page transitions.
4. Separation of Frontend and Backend
- SPA promotes a clean separation between the UI (frontend) and business logic (backend via APIs/REST).
- Frontend frameworks like React, Angular, Vue.js are commonly used to build SPAs.
5. Offline Capability
- SPAs can work offline or with poor connectivity using browser caching and service workers (Progressive Web Apps).
6. Easy Debugging and Testing
- Developer tools in browsers allow easy inspection of network calls and component states.
- Frontend and backend can be tested independently.
7. Reusability
- The same backend API can serve the SPA as well as mobile applications, promoting code reuse.
How SPA Works (Brief)
User visits URL
|
Browser loads single HTML + CSS + JS bundle
|
User clicks/interacts
|
JavaScript handles routing (client-side routing)
|
AJAX/Fetch call to server API (returns JSON)
|
DOM is updated dynamically (no full reload)
Limitations (for completeness)
- Poor SEO by default (search engines may not index dynamic content easily).
- Initial load time can be slow due to large JS bundles.
- Requires JavaScript to be enabled in the browser.
Summary Table
| Feature | SPA | Traditional Web App |
|---|---|---|
| Page Reload | No | Yes |
| Speed | Fast | Slower |
| Server Load | Less | More |
| SEO | Difficult | Easy |
| User Experience | Smooth | Flickering |
In conclusion, SPA is widely used in modern web development because it provides a fast, interactive, and seamless user experience by dynamically rendering content on the client side without full page reloads.
React email and phone validation
0 · 5 marks
Write a program to validate email id and phone number using React. [5]
Show solved answerHide answer
React Program to Validate Email ID and Phone Number
Given
This is a programming/implementation question, not a numerical problem. There is no numeric data (no matrices, burst times, page strings, etc.) to extract.
Requirements from the question:
- Framework: React
- Validate: Email ID and Phone Number
- Marks: 5 (implies a complete working component with validation logic)
No numeric inputs are missing because none are required for this task.
STEP 2 - SOLVE: Model Answer
The standard approach uses functional components with the useState hook, controlled inputs, and regular expressions for validation.
import React, { useState } from 'react';
function ValidationForm() {
const [email, setEmail] = useState('');
const [phone, setPhone] = useState('');
const [emailError, setEmailError] = useState('');
const [phoneError, setPhoneError] = useState('');
const [successMsg, setSuccessMsg] = useState('');
// Email validation using RegEx
const validateEmail = (value) => {
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!value) return 'Email is required.';
if (!emailRegex.test(value)) return 'Invalid email format.';
return '';
};
// Phone validation (10-digit number)
const validatePhone = (value) => {
const phoneRegex = /^[0-9]{10}$/;
if (!value) return 'Phone number is required.';
if (!phoneRegex.test(value)) return 'Phone must be exactly 10 digits.';
return '';
};
const handleSubmit = (e) => {
e.preventDefault();
const emailErr = validateEmail(email);
const phoneErr = validatePhone(phone);
setEmailError(emailErr);
setPhoneError(phoneErr);
if (!emailErr && !phoneErr) {
setSuccessMsg('Email and Phone Number are valid!');
} else {
setSuccessMsg('');
}
};
return (
<div style={{ padding: '30px', maxWidth: '400px', margin: 'auto' }}>
<h2>Email and Phone Validation</h2>
<form onSubmit={handleSubmit}>
<div style={{ marginBottom: '15px' }}>
<label>Email ID:</label>
<input
type="text"
value={email}
onChange={(e) => setEmail(e.target.value)}
placeholder="Enter your email"
/>
{emailError && <p style={{ color: 'red' }}>{emailError}</p>}
</div>
<div style={{ marginBottom: '15px' }}>
<label>Phone Number:</label>
<input
type="text"
value={phone}
onChange={(e) => setPhone(e.target.value)}
placeholder="Enter 10-digit phone number"
/>
{phoneError && <p style={{ color: 'red' }}>{phoneError}</p>}
</div>
<button type="submit">Validate</button>
{successMsg && <p style={{ color: 'green' }}>{successMsg}</p>}
</form>
</div>
);
}
export default ValidationForm;
Explanation of Key Parts
| Concept | Purpose |
|---|---|
useState | Stores input values and error/success messages |
Controlled inputs (value + onChange) | Keeps React state synced with input fields |
e.preventDefault() | Stops the browser from reloading on submit |
| Email regex | /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/ matches [email protected] |
| Phone regex | /^[0-9]{10}$/ accepts exactly 10 digits |
Email regex breakdown:
[a-zA-Z0-9._%+-]+: local part (letters, digits, common symbols)@: mandatory at-symbol[a-zA-Z0-9.-]+: domain\.[a-zA-Z]{2,}$: dot + top-level domain of 2+ letters
Phone regex breakdown:
^[0-9]{10}$: ensures the string is only 10 numeric characters
Sample Behaviour
- Input
[email protected]and9812345678-> "Email and Phone Number are valid!" (green) - Input
ramgmail.com-> "Invalid email format." (red) - Input phone
98123-> "Phone must be exactly 10 digits." (red)
Make Unit 8 stick
Practice BIT351 with flashcards & quizzes