Day 10 · 1 Hour
Frontend Development
The UI that users actually touch — HTML, CSS, and JavaScript calling your API.
🔥 Real-World Hook (0–5 min)
Your backend API is perfect — but users never touch it directly. They use the frontend. Swiggy's ₹100 crore revenue comes from a beautiful, fast React UI that makes ordering feel effortless.
Today you build a real student dashboard with HTML, CSS, and JavaScript that calls your Spring Boot API — the complete frontend of a full-stack app.
🖥 The 3-Layer Frontend (5–20 min)
💡 Analogy
HTML — The skeleton (structure, bones).
CSS — The skin and clothes (appearance, layout).
JavaScript — The muscles (behaviour, interaction, API calls).
💻 Live Coding — Student Dashboard (20–40 min)
<!-- HTML structure --> <div id="app"> <h1>Student Dashboard</h1> <form id="addForm"> <input id="nameInput" placeholder="Name" required> <input id="emailInput" placeholder="Email" type="email"> <button type="submit">Add Student</button> </form> <div id="studentList"></div> </div>
// JavaScript: fetch API to talk to Spring Boot const API = 'http://localhost:8080/api/students'; async function loadStudents() { const res = await fetch(API); const data = await res.json(); document.getElementById('studentList').innerHTML = data.map(s => ` <div class="student-card"> <strong>${s.name}</strong> — ${s.dept} <button onclick="deleteStudent(${s.id})">🗑</button> </div> `).join(''); } document.getElementById('addForm').addEventListener('submit', async e => { e.preventDefault(); await fetch(API, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ name: document.getElementById('nameInput').value, email: document.getElementById('emailInput').value }) }); loadStudents(); }); async function deleteStudent(id) { await fetch(`${API}/${id}`, { method: 'DELETE' }); loadStudents(); } loadStudents();
🎯 You Code It (40–55 min)
- Create
index.htmlwith a form: product name, price, category - Write JavaScript that loads products from your Spring Boot API on page load
- Display each product as a card with name, price, and a delete button
- The form submit should POST to your API and reload the list
- Add a search input that filters the displayed cards by name (client-side, no API call)
- Show: Add 3 products via the form, search for one, delete one
📄 Day 10 Cheat Sheet — Frontend
DOM Basics
| document.getElementById("id") | Get element |
| element.innerHTML = "..." | Set HTML content |
| element.value | Input field value |
| element.style.display | Show/hide |
| element.classList.add("x") | Add CSS class |
Fetch API
| fetch(url) | GET request |
| res.json() | Parse JSON body |
| method: 'POST' | POST request |
| headers: {Content-Type: 'application/json'} | JSON header |
| body: JSON.stringify(obj) | Serialize body |
| await / async | Handle promises |
Events
| el.addEventListener('click', fn) | Click event |
| el.addEventListener('submit', fn) | Form submit |
| el.addEventListener('input', fn) | On typing |
| e.preventDefault() | Stop default |
| e.target.value | Input value |
Template Literals
| `Hello ${name}` | Embed variable |
| arr.map(x => `<li>${x}</li>`).join('') | List to HTML |
| JSON.stringify(obj) | Object to JSON |
| JSON.parse(str) | JSON to object |
| localStorage.setItem(k,v) | Save locally |