CoachnestCoachnest
Sign InGet Started
Back to course

Mastering CRUD: Build Full-Stack Database Applications

…
—
Contents
1

What Is CRUD and Why It Matters

Reading12mFree
2

CRUD, REST, and HTTP Verbs

Reading14mFree
3

The Data Lifecycle of a Record

Reading11m
4

Course Project Tour: TaskFlow

Video9m
5

Chapter 1 — Quiz

Quiz8m
6

Tables, Rows, Columns & Types

Reading14m
7

Primary Keys & IDs (Auto-increment vs UUID)

Reading13m
8

Relationships: One-to-Many & Many-to-Many

Reading16m
9

Normalization & Schema Design Principles

Reading14m
10

Modeling TaskFlow with Prisma

Reading13m
11

Chapter 2 — Quiz

Quiz8m
12

INSERT — Creating Rows

Reading13m
13

SELECT — Reading & Filtering

Reading16m
14

UPDATE — Changing Rows Safely

Reading12m
15

DELETE — Removing Rows

Reading11m
16

Live SQL: A Full CRUD Session

Video15m
17

Chapter 3 — Quiz

Quiz9m
18

REST API Design for CRUD Resources

Reading14m
19

HTTP Status Codes That Tell the Truth

Reading12m
20

Scaffolding the API (Express & Next.js)

Reading16m
21

Connecting an ORM (Prisma) to Your Routes

Reading13m
22

Chapter 4 — Quiz

Quiz8m
23

Building the Create Endpoint End-to-End

Reading15m
24

Reading a Single Resource

Reading11m
25

Listing Collections

Reading13m
26

Live Coding: Create & Read

Video16m
27

Chapter 5 — Quiz

Quiz8m
28

PUT vs PATCH: Full vs Partial Updates

Reading13m
29

Authorization: Who Can Change This Row?

Reading12m
30

Soft Delete, Hard Delete & Restore

Reading14m
31

Idempotency & Concurrency Control

Reading13m
32

Chapter 6 — Quiz

Quiz9m
33

Input Validation with Zod

Reading14m
34

Mass Assignment & Over-Posting

Reading11m
35

SQL Injection & Safe Queries

Reading13m
36

Consistent Error Handling

Reading12m
37

Chapter 7 — Quiz

Quiz9m
38

Offset vs Cursor Pagination

Reading15m
39

Filtering & Dynamic WHERE Clauses

Reading13m
40

Safe Sorting & Full-Text Search

Reading14m
41

Indexing for Fast Reads

Reading13m
42

Chapter 8 — Quiz

Quiz9m

Forms & Creating Records from the UI

Reading14m
44

Fetching & Displaying Data

Reading13m
45

Optimistic Updates & Deletes

Reading14m
46

Building the TaskFlow UI

Video17m
47

Chapter 9 — Quiz

Quiz8m
48

Transactions & Data Integrity

Reading15m
49

Testing Your CRUD Endpoints

Reading14m
50

Caching, N+1 & Performance

Reading13m
51

Deploying & Migrating Safely

Reading14m
52

Chapter 10 — Final Quiz

Quiz10m
←→navigate lessons
Chapter 9 of 10·Chapter 9 — CRUD on the Frontend
Lesson 43 of 52Reading14 min

Forms & Creating Records from the UI

Forms & Creating Records from the UI¶

The user-facing side of Create is a form. Done well, it validates early, handles errors, and never double-submits.

A Controlled Form¶

tsx
42 lines
1"use client";
2import { useState } from "react";
3
4export function NewTaskForm({ onCreated }: { onCreated: (t: Task) => void }) {
5  const [title, setTitle] = useState("");
6  const [submitting, setSubmitting] = useState(false);
7  const [error, setError] = useState<string | null>(null);
8
9  async function handleSubmit(e: React.FormEvent) {
10    e.preventDefault();
11    setSubmitting(true);
12    setError(null);
13    try {
14      const res = await fetch("/api/v1/tasks", {
15        method: "POST",
16        headers: { "Content-Type": "application/json" },
17        body: JSON.stringify({ title }),
18      });
19      if (!res.ok) {
20        const body = await res.json();
21        throw new Error(body.error?.message ?? "Failed to create task");
22      }
23      const { data } = await res.json();
24      onCreated(data);
25      setTitle("");
26    } catch (err) {
27      setError((err as Error).message);
28    } finally {
29      setSubmitting(false);
30    }
31  }
32
33  return (
34    <form onSubmit={handleSubmit}>
35      <input value={title} onChange={(e) => setTitle(e.target.value)} required />
36      <button disabled={submitting || !title.trim()}>
37        {submitting ? "Saving…" : "Add task"}
38      </button>
39      {error && <p role="alert">{error}</p>}
40    </form>
41  );
42}

Three Things This Form Gets Right¶

  1. 1.Disables the button while submitting — prevents double-creates.
  2. 2.Surfaces server errors — the user sees why it failed.
  3. 3.Clears on success — ready for the next entry.

Validate on the Client AND the Server¶

Client validation is for UX (instant feedback). Server validation is for safety (it's the only one an attacker can't bypass). Do both — reuse the same Zod schema on both sides if you can.

Server Actions: Forms Without fetch¶

In Next.js you can post a form straight to a server function — progressive enhancement, works without JS:

tsx
4 lines
1<form action={createTask}>
2  <input name="title" required />
3  <button>Add</button>
4</form>

Previous

Chapter 8 — Quiz

Next

Fetching & Displaying Data

Use ← → arrow keys to navigate between lessons