Httpd_router - A routing module for OTP's built-in httpd web server

Erlang OTP comes with a built in webserver, the inets httpd server

httpd_router implements the do/1 callback expected by the
httpd module pipeline, providing clean, declarative routing without
external dependencies.

Features:

  • Declarative route registration with path patterns (e.g. /users/:id)

  • Middleware chains for cross-cutting concerns (auth, logging, CORS)

  • CRUD route shortcuts ("CRUD", "CR", "RD", etc.)

  • Automatic OPTIONS/CORS preflight handling (pending OTP patch issued…)

  • Clean request context map passed to handlers

  • Multiple named route tables for different server instances

  • Streaming response support

  • Configurable fallthrough behaviour (404 or passthrough to next module)

  • Zero external dependencies — pure OTP

For all the details, including examples see here:

8 Likes

I really like the idea! I think this would fit well for OTP’s httpd and perhaps “modernize” it.
Stay tuned and have an eye out for inets PRs (or maybe try opening your own :smiley:)

Best regards,
Konrad

1 Like

Maybe also interesting to check our dispatch rule compiler:

Very cool!

Do you have any guidance as to when one might pick httpd over the third party http servers such as Elli, Cowboy, etc?

I think the most obvious answer for me is “pick httpd over something else, when you want to limit the amount of 3pps and external dependencies as much as possible”. We aim to improve the inets application as a whole, but there is so much we can do, without creating a new client/server. I think the goal is to make both client and server usable and stable, and by doing so, not give users too many headaches.

Best regards,
Konrad

Aye, but what is the trade off there? I always want fewer dependencies, so if that’s the only consideration I always want to use httpd.

Lack of HTTP2/3, SSE, and WS are one thing. Is there anything else? Perhaps httpd has significant performance limitations or resource usage?

I cannot think of any obvious performace/memory limitations inside of httpd, from the top of my head. Inets’ httpd was designed some time ago and is constantly improved and maintained. It is a good choice if it fits your needs (HTTP/1.1, no WS). I am sure, the best way to know for yourself if httpd is good enough for you, in the end, is to do your own benchmarks. My reason for that is, who else if not you yourself, understands your needs better. From my point of view, httpc and httpd were never designed to be blazingly fast, but that doesn’t mean it won’t be good enough for the use case you are after.

Here are some numbers:

2 Likes