Menu

I Added Koa Support to My Universal Boilerplate (And It Was Tricky)
πŸ“°

I Added Koa Support to My Universal Boilerplate (And It Was Tricky)

DEV Community: koaΒ·Adam GolanΒ·8 months ago
#uRdPPxNw
#devtokoa#devto#dev#express#fastify
Long article (423 words) β€” no AI summary yet.
Reading 0:00
15s threshold

The Challenge 🐨

I recently built BEnder , a framework-agnostic boilerplate that runs on Express , Fastify , Hono , or Elysia using a single codebase.

Adding Koa is another to single truth concept.

The Problem: Context vs. Req/Res

Most Node frameworks (Express, Fastify) follow the standard callback signature:

( req , res ) => void

Enter fullscreen mode

Exit fullscreen mode

Koa , however, uses a Context object:

( ctx , next ) => Promise < void >

Enter fullscreen mode

Exit fullscreen mode

This broke my unified IRequest and IResponse interfaces. My "Synapses" (route handlers) expected to call res.json() , but Koa expects you to set ctx.body .

The Solution: The Adapter Pattern 🧩

I wrote a KoaRouterShim that wraps every handler.…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.