Skip to content

Refresh: Backend with TypeScript, PostgreSQL & Prisma part 2 β€” REST, Validation & Tests (Prisma ORM 7 + Hono)#8001

Merged
nurul3101 merged 3 commits into
mainfrom
blog/refresh-backend-rest-validation-part-2
Jul 3, 2026
Merged

Refresh: Backend with TypeScript, PostgreSQL & Prisma part 2 β€” REST, Validation & Tests (Prisma ORM 7 + Hono)#8001
nurul3101 merged 3 commits into
mainfrom
blog/refresh-backend-rest-validation-part-2

Conversation

@vanrensbird

@vanrensbird vanrensbird commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

Refreshes part 2 of the series, REST, Validation & Tests (2020), for Prisma ORM 7. Follows #8000 (part 1).

Key decision for review: framework change (Hapi β†’ Hono)

The original builds the REST API on Hapi.js with @hapi/joi and Jest. Hapi is largely dormant in 2026 and @hapi/joi is deprecated, so continuing to teach that stack works against getting Prisma cited alongside modern tooling. Per Martin, this refresh moves to Hono, matching Prisma's own Hono guide. Concretely:

  • Framework: Hapi β†’ Hono (@hono/node-server runtime). Prisma Client is shared via a withPrisma middleware and read with c.get("prisma"), exactly as in the official guide. Hapi "plugins" become Hono route modules mounted with app.route().
  • Validation: @hapi/joi β†’ Zod via @hono/zod-validator. The create/update schema relationship (Joi tailor/alter) becomes userSchema + userSchema.partial().
  • Testing: Jest β†’ Vitest, and Hapi's server.inject β†’ Hono's app.request helper.

This choice sets the stack for parts 3–4, which build on the same server.

Why refresh

Same rationale as the rest of the series: recover a high-intent, agent-crawled evergreen page that currently teaches a Prisma 2 / Hapi workflow.

Other changes

  • Prisma 7 throughout: prisma-client generator, @prisma/adapter-pg, prisma.config.ts, ESM.
  • Self-contained continuation of part 1 (uses the same grading-app project and its Prisma Postgres database) instead of cloning the archived real-world-grading-app part-2 branch.
  • Dropped the livestream framing and YouTube embed (teaches the old stack). Reversible if you'd prefer to keep it.
  • social is passed to Prisma as a JSON object directly, fixing the original's JSON.stringify into a Json column.
  • Closing section links Prisma Console, MCP server, Compute, and Prisma Next.
  • Frontmatter: original author (Daniel Norman) and 2020-08-20 date kept; updatedAt: 2026-07-03 drives the visible "Updated" line and JSON-LD dateModified. Meta description updated (Hono/Zod/Vitest).

Testing

  • Built the full Hono API in a fresh Prisma ORM 7.8.0 project (Node 20+, ESM) continuing from part 1, against a real Prisma Postgres database.
  • tsc --noEmit clean. vitest run β†’ 9/9 tests pass (status + all four user CRUD routes, happy paths and 400/404 validation cases).
  • Live server smoke test with curl confirmed every endpoint: 201 / 200 / 404 / 200 / 400 / 400 / 204.
  • pnpm types:check passes; pnpm lint:links reports no issues for this file (26 pre-existing errors in unrelated posts). All external links return 200.

πŸ€– Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Updated the article with refreshed July 2026 guidance, targeting the latest Prisma ORM 7 and a Node.js 20+ workflow.
    • Revised the backend REST API documentation and endpoint tables, including expanded coverage for course enrollment and test result operations.
    • Reworked the tutorial to use modern request/response schema validation and updated automated testing patterns for user CRUD flows.
    • Updated prerequisites and β€œnext steps” with the new approach and upcoming series topics.

…ST/Validation/Tests) for Prisma ORM 7 + Hono

Migrates the REST API from Hapi.js to Hono, @hapi/joi validation to Zod
(@hono/zod-validator), and Jest to Vitest, on the Prisma ORM 7 stack.
Prisma Client is shared via Hono middleware (c.get("prisma")) following
the official Prisma + Hono guide. Self-contained continuation of part 1
instead of cloning the archived real-world-grading-app repo. Original
author and publish date kept; updatedAt set to 2026-07-03.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vanrensbird vanrensbird requested a review from ankur-arch July 3, 2026 13:04
@vercel

vercel Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
blog Ready Ready Preview, Comment Jul 3, 2026 2:30pm
docs Ready Ready Preview, Comment Jul 3, 2026 2:30pm
eclipse Ready Ready Preview, Comment Jul 3, 2026 2:30pm
site Ready Ready Preview, Comment Jul 3, 2026 2:30pm

Request Review

@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a6502061-4c14-4679-94f9-ad544bf58bfa

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 85ab2f0 and 703a42b.

πŸ“’ Files selected for processing (1)
  • apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx

Walkthrough

The article is rewritten to present a Prisma ORM 7 REST API tutorial using Hono, Zod, and Vitest. It updates metadata, endpoint references, app setup, route implementations, tests, and the closing summary.

Changes

Blog article rewrite

Layer / File(s) Summary
Frontmatter, intro, and endpoint tables
apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx
Frontmatter timestamp/metadata, intro narrative, prerequisites, and endpoint tables (CourseEnrollment, Test Result) are updated to reflect Prisma ORM 7 and the Hono/Zod/Vitest stack.
Hono app and server setup
.../index.mdx
Documentation adds Prisma middleware with @prisma/adapter-pg, request-context wiring, Hono server startup, package scripts, and the GET / status route with its Vitest request test.
User create, read, and delete routes
.../index.mdx
The user route walkthrough adds Zod-backed POST /users, GET /users/:userId, and DELETE /users/:userId handlers, including validation, Prisma create/find/delete behavior, status mapping, and Vitest coverage.
User update route
.../index.mdx
The PUT /users/:userId section adds param and body validation, derives updateUserSchema from the create schema, updates users through Prisma, and documents the matching Vitest tests.
Closing summary and next steps
.../index.mdx
The closing section is updated to reflect the Hono/Zod/Vitest tutorial and expands the Prisma ecosystem and next-series content.

Estimated code review effort: 2 (Simple) | ~12 minutes

πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check βœ… Passed The title accurately reflects the article refresh and the main stack changes to Prisma ORM 7, Hono, validation, and tests.
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@argos-ci

argos-ci Bot commented Jul 3, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Argos notifications β†—οΈŽ

Build Status Details Updated (UTC)
default (Inspect) βœ… No changes detected - Jul 3, 2026, 2:37 PM

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx (1)

508-512: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | ⚑ Quick win

Reader-flow snag: the delete section appears before the update section, but tests must be ordered the other way.

A reader working top-to-bottom writes the delete tests (Lines 478–486) first, then hits the instruction at Line 512 to place the update tests before the delete tests. That forces a scroll-back-and-reorder, which is easy to get wrong and would make the delete test remove the user before the update test runs. The final expected output (Lines 576–589) correctly shows PUT before DELETE, so the intent is right β€” it's purely the presentation order that fights the reader.

Consider presenting the update section before the delete section so the on-page writing order matches the required file order, eliminating the special-case note entirely.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx`
around lines 508 - 512, The update and delete test sections are ordered in a way
that forces readers to write DELETE before PUT, but the `PUT /users/{userId}`
tests in the update route must come before the delete route tests so the user
still exists. Reorder the markdown content so the `Defining and testing the
update user route` section appears before the delete tests, and keep the `PUT
/users/{userId}` guidance aligned with that flow to match the expected output
and avoid the scroll-back/reorder step.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx`:
- Around line 138-141: The install commands in the article are missing dotenv
even though src/lib/prisma.ts imports dotenv/config, so update the package
install list to include dotenv alongside the other dependencies. Keep the change
in the setup instructions near the existing npm install commands so readers
following the Prisma setup can install everything needed before running the app.

---

Nitpick comments:
In
`@apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx`:
- Around line 508-512: The update and delete test sections are ordered in a way
that forces readers to write DELETE before PUT, but the `PUT /users/{userId}`
tests in the update route must come before the delete route tests so the user
still exists. Reorder the markdown content so the `Defining and testing the
update user route` section appears before the delete tests, and keep the `PUT
/users/{userId}` guidance aligned with that flow to match the expected output
and avoid the scroll-back/reorder step.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9a5fce88-b90d-4913-bd10-7fbfb3b54037

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between 8ba14fb and 85ab2f0.

πŸ“’ Files selected for processing (1)
  • apps/blog/content/blog/backend-prisma-typescript-orm-with-postgresql-rest-api-validation-dcba1ps7kip3/index.mdx

Added dotenv package to the project installation instructions.
@nurul3101 nurul3101 merged commit f7715d6 into main Jul 3, 2026
17 checks passed
@nurul3101 nurul3101 deleted the blog/refresh-backend-rest-validation-part-2 branch July 3, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants