Syntax Video
Build a documented /Β type-safe API with hono, drizzle, zod, OpenAPI and scalar
In this video CJ shows how to use hono and @hono/zod-openapi to build a fully type-safe API documented with an OpenAPI specification including interactive documentation with scalar. He also shows hono best practices and shows some things you should do / setup in every hono app you create. He also shows how to use a drizzle schema as the single source of truth for type safety and documentation throughout your application. He also shows how to use vitest to write typesafe tests for your API.
- 0:00 Intro
- 1:10 Quick Code Tour
- 2:51 stoker - a hono library
- 3:19 hono-open-api-starter
- 4:00 generate hono app
- 4:50 eslint / editor settings setup
- 7:11 typescript import alias
- 7:41 install @hono/zod-openapi
- 8:10 extract hono app to own file
- 9:43 notFound handler
- 11:30 onError handler
- 13:08 logger middleware
- 13:52 structured logging with pino and hono-pino
- 15:46 hono-pino pretty logs and customization
- 20:23 typesafe hono AppBindings
- 21:56 pino log level setting
- 23:35 dotenv setup
- 25:30 typesafe env with zod
- 32:25 serveEmojiFavicon middleware
- 33:33 clean up app creation
- 35:36 hono strict mode
- 36:16 configure openapi doc endpoint
- 38:36 createRouter helper
- 39:33 create index route
- 42:42 mount index router on application
- 44:02 open api overview
- 45:00 scalar documentation setup
- 46:30 package.json type module
- 47:00 scalar customization
- 49:21 OpenAPIHono defaultHook
- 50:48 stoker openapi helpers
- 54:01 group route definitions with tags
- 54:34 tasks router setup
- 55:32 tasks list route
- 57:22 tasks list handler
- 57:45 RouteHandler type setup
- 59:48 AppRouteHandler custom type
- 1:01:21 register tasks list route and handler
- 1:02:32 tasks route tags
- 1:02:55 drizzle setup
- 1:03:50 DATABASE_URL env setup
- 1:04:52 zod superRefine for better errors
- 1:05:42 setup drizzle schema
- 1:08:49 drizzle-kit config setup
- 1:09:59 generate drizzle migrations
- 1:10:51 using drizzle-kit studio
- 1:11:27 update schema date logic
- 1:12:44 query db from tasks list handler
- 1:14:28 drizzle-zod setup
- 1:16:06 tasks create route
- 1:20:01 tasks create handler
- 1:25:06 stoker createErrorSchema helper
- 1:27:46 customize drizzle-zod schema
- 1:29:37 tasks getOne route
- 1:33:17 tasks getOne handler
- 1:38:37 tasks patch route
- 1:44:08 tasks patch handler
- 1:47:41 tasks remove route
- 1:49:17 tasks remove handler
- 1:51:15 test setup / helpers with vitest
- 1:59:23 typed test client helper
- 2:05:33 full test setup walkthrough
- 2:07:20 hono RPC client type
- 2:09:57 hono client example
- 2:11:03 open api client generators
- 2:11:40 runtime and deployment considerations
- 2:12:17 Thanks!