CJ demonstrates how to build a fully type-safe, documented API using Hono, Drizzle ORM, Zod, OpenAPI, and Vitest.
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.
View the code here: github.com/w3cj/hono-open-api-starter
View the stoker utilities / helpers here: github.com/w3cj/stoker
Intro
Quick Code Tour
stoker - a hono library
hono-open-api-starter
generate hono app
eslint / editor settings setup
typescript import alias
install @hono/zod-openapi
extract hono app to own file
notFound handler
onError handler
logger middleware
structured logging with pino and hono-pino
hono-pino pretty logs and customization
typesafe hono AppBindings
pino log level setting
dotenv setup
typesafe env with zod
serveEmojiFavicon middleware
clean up app creation
hono strict mode
configure openapi doc endpoint
createRouter helper
create index route
mount index router on application
open api overview
scalar documentation setup
package.json type module
scalar customization
OpenAPIHono defaultHook
stoker openapi helpers
group route definitions with tags
tasks router setup
tasks list route
tasks list handler
RouteHandler type setup
AppRouteHandler custom type
register tasks list route and handler
tasks route tags
drizzle setup
DATABASE_URL env setup
zod superRefine for better errors
setup drizzle schema
drizzle-kit config setup
generate drizzle migrations
using drizzle-kit studio
update schema date logic
query db from tasks list handler
drizzle-zod setup
tasks create route
tasks create handler
stoker createErrorSchema helper
customize drizzle-zod schema
tasks getOne route
tasks getOne handler
tasks patch route
tasks patch handler
tasks remove route
tasks remove handler
test setup / helpers with vitest
typed test client helper
full test setup walkthrough
hono RPC client type
hono client example
open api client generators
runtime and deployment considerations
Thanks!
hono | hono.dev/
@hono/zod-openapi | github.com/honojs/middleware/tree/main/packages/zod-openapi
scalar | scalar.com/
What is Open API? | swagger.io/docs/specification/v3_0/about/
stoker | npmjs.com/package/stoker
zod | zod.dev/
@antf
Why it's here
3 people recommend this
What people say. Recommended as a high-quality, comprehensive guide to building modern type-safe APIs with Hono and Drizzle.
w
u/whiterhino8in r/node • Recommends
On “I think I like Hono js am I doing right ?”
Sound good . Good luck with your project .
I am now building this API .
Works out of the box .
Just need to learn how configure it to my needs and master it .
https://github.com/w3cj/hono-open-api-starter
[video
awesome API