Unit 3 of 3 · BCA Sem 3

Unit 3: Backend development and databases

Web Programming-I notes · PTU syllabus (UGDSE301)

3 min read5 topics9 exam questions
On this page
  1. Unit summary
  2. Server-side programming with Node.js and Express
  3. Sessions and cookies on the server
  4. Databases: relational and NoSQL
  5. CRUD operations
  6. JSON and REST APIs
  7. Key terms
  8. Quick revision
  9. Important questions

Unit summary

Modern web applications are built as a backend that serves data and a database that stores it. This unit introduces server-side programming with Node.js/Express or PHP, routing GET and POST requests, sessions and cookies, relational and NoSQL databases (MySQL, PostgreSQL, MongoDB), CRUD operations, and JSON-based REST APIs.

After this unit you can

  • Explain the role of a backend and create routes with Express.js
  • Handle GET and POST requests and manage sessions
  • Perform CRUD operations by connecting a backend to a database
  • Design and use JSON REST APIs

PTU syllabus topics

  • Introduction to server-side programming with Node.js or PHP
  • Express.js routing
  • handling GET/POST requests
  • session and cookie management
  • introduction to MySQL/PostgreSQL/MongoDB
  • CRUD operations
  • connecting backend to database
  • JSON and REST APIs
ComparisonCRUD to HTTP and SQL
HTTP method
SQL

Create

POST

INSERT

Read

GET

SELECT

Update

PUT / PATCH

UPDATE

Delete

DELETE

DELETE

1

Topic 1

Server-side programming with Node.js and Express

Node.js runs JavaScript on the server; Express.js is a lightweight framework for building web servers and APIs on Node.

javascriptconst express = require("express");
const app = express();
app.use(express.json());                 // parse JSON bodies

app.get("/students", (req, res) => {     // GET route
  res.json([{ roll: 1, name: "Ana" }]);
});
app.post("/students", (req, res) => {    // POST route
  const s = req.body;
  res.status(201).json({ message: "Created", student: s });
});
app.listen(3000);

Routing maps a URL and HTTP method to a handler function. Route parameters (/students/:id) read values from the URL.

2

Topic 2

Sessions and cookies on the server

Express uses middleware such as express-session and cookie-parser; PHP uses session_start() and $_SESSION. Sessions keep users logged in across requests; cookies store a session ID in the browser.

3

Topic 3

Databases: relational and NoSQL

ComparisonSQL vs NoSQL databases
Relational (MySQL, PostgreSQL)
NoSQL (MongoDB)

Structure

Tables with fixed schema

Flexible JSON-like documents

Query language

SQL

Query objects / methods

Relationships

Joins and foreign keys

Embedded documents or references

Best for

Structured, transactional data

Rapidly changing or large unstructured data

4

Topic 4

CRUD operations

CRUD = Create, Read, Update, Delete — the four basic data operations.

OperationSQLHTTP methodMongoDB
CreateINSERTPOSTinsertOne()
ReadSELECTGETfind()
UpdateUPDATEPUT / PATCHupdateOne()
DeleteDELETEDELETEdeleteOne()
php<?php
$conn = new mysqli("localhost", "root", "", "college");
$stmt = $conn->prepare("INSERT INTO student (name, course) VALUES (?, ?)");
$stmt->bind_param("ss", $name, $course);   // prepared statement prevents SQL injection
$stmt->execute();
?>
5

Topic 5

JSON and REST APIs

JSON is the standard data format for APIs: {"roll": 1, "name": "Ana", "courses": ["BCA"]}. A REST API exposes resources at URLs and uses HTTP methods to act on them, returning JSON and status codes.

Key termsCommon HTTP status codes
200 OK
Request succeeded
201 Created
A new resource was created
400 Bad Request
Invalid input
404 Not Found
Resource does not exist
500 Internal Server Error
Server-side failure

Exam tip

REST principles: resources identified by URLs, standard HTTP methods, stateless requests and JSON representations.

Key terms

Backend
The server-side part of an application handling logic and data
Express.js
A minimal web framework for Node.js
Route
A mapping from URL and method to a handler
CRUD
Create, read, update and delete operations
REST API
An interface using URLs and HTTP methods to work with resources

Quick revision

  • app.get / app.post define routes in Express.
  • SQL: tables and joins; NoSQL: flexible documents.
  • CRUD ↔ POST, GET, PUT/PATCH, DELETE.
  • Use prepared statements to prevent SQL injection.
  • 200 OK, 201 Created, 404 Not Found, 500 Server Error.

Important exam questions

Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).

Short-answer questions

  1. Q1.What is Node.js?
  2. Q2.What is routing in Express?
  3. Q3.Differentiate between SQL and NoSQL databases.
  4. Q4.Expand CRUD and map it to HTTP methods.
  5. Q5.What is a REST API?
  6. Q6.Why are prepared statements used?

Long-answer questions

  1. Q1.Explain how to build a simple REST API with Express.js for student records.
  2. Q2.Explain CRUD operations with SQL queries and a PHP-MySQL example.
  3. Q3.Compare relational and NoSQL databases with examples.

Stuck on this unit?

Message SBS on WhatsApp for help with Web Programming-I, or to ask about studying BCA at Synetic.

WhatsApp us