Matthew Burns

December 21, 2023

Cloudflare Workers - Routing Made Easy

Note: This previously appeared February 4, 2023 on my old blog platform.


Hi, just wanted to share something cool I found while working on a side project using Cloudflare Workers. It’s called itty-router-openapi and it’s from Cloudflare themselves. 


I’ve been working on a globally distributed server provisioning platform using Cloudflare’s compute (Workers) and storage (KV, R2, Durable Objects.) As part of the API portion of this work, I first rolled my own naive implementation of endpoint routing to get things off the ground. After building up the service further it, was becoming apparent that I would need a proper routing framework.


I first started working on my own framework but that quickly turned into something I really didn’t want to dig into and I (correctly) assumed that this had been solved somewhere else first. The first thing I landed on was itty-router. It’s a micro routing framework that works with Javascript and TypeScript that seemed to fit the bill perfectly for what I needed.


I started rewriting my endpoints using this framework. As I was running into issues, I started searching around for additional documentation or sites when I stumbled upon itty-router-openapi. Seeing that it was intended for use with Workers, been used in production for Cloudflare Radar and had the added support for OpenAPI, I was instantly sold.


I’ve only now started the third re-write using this new library. So far it has been going pretty good but I will try to update soon on how things are going and if I’m still using the framework.

About Matthew Burns

Software Engineer at Equinix Metal. Server whisperer. Aspiring Quantum Engineer.
3D Movies List