<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged http-server</title>
<link>https://coderlegion.com/tag/http-server</link>
<description>Powered by Question2Answer</description>
<item>
<title>Adding OpenAPI Support to Mummy, a Nim HTTP Framework</title>
<link>https://coderlegion.com/27091/adding-openapi-support-to-mummy-a-nim-http-framework</link>
<description>&lt;h2 id=&quot;adding-openapi-support-to-mummy-lessons-from-extending-nim-s-thread-per-request-http-server&quot;&gt;Adding OpenAPI Support to Mummy: Lessons from Extending Nim's Thread-Per-Request HTTP Server&lt;/h2&gt;
&lt;p&gt;Mummy is a multi-threaded HTTP 1.1 and WebSocket server for Nim built around a simple, unapologetic idea: skip &lt;code&gt;async&lt;/code&gt;/&lt;code&gt;await&lt;/code&gt; entirely and let a pool of worker threads handle requests the old-fashioned way — one thread, one request, blocking calls allowed. No &lt;code&gt;Future[T]&lt;/code&gt;, no colored functions, no async stack traces to untangle. For a systems language with real threads and ARC/ORC to make that cheap, it's a compelling trade.&lt;/p&gt;
&lt;p&gt;What Mummy doesn't ship with, though, is any notion of API documentation. There's no built-in way to describe your routes, generate a schema, or hand a frontend team (or your future self) a &lt;code&gt;/docs&lt;/code&gt; page. That gap is what got me building.&lt;/p&gt;
&lt;h3 id=&quot;why-this-gap-matters&quot;&gt;Why This Gap Matters&lt;/h3&gt;
&lt;p&gt;Nim's web ecosystem is small enough that most frameworks are optimized for the author's own use case first. Mummy is optimized for raw throughput and simplicity — and it succeeds at both. But once an API has more than a couple of routes, &quot;read the source to find out what a request body looks like&quot; stops scaling. OpenAPI (formerly Swagger) solves this by generating a machine-readable schema of your API directly from your code, which then powers interactive docs, client SDK generation, and request validation.&lt;/p&gt;
&lt;p&gt;I forked Mummy and built this in as a layer on top, rather than a separate tool that has to be kept in sync by hand.&lt;/p&gt;
&lt;h3 id=&quot;what-i-built&quot;&gt;What I Built&lt;/h3&gt;
&lt;p&gt;The fork adds two core modules — &lt;code&gt;openapi_schema.nim&lt;/code&gt; and &lt;code&gt;openapi_router.nim&lt;/code&gt; — plus an &lt;code&gt;OpenApiRouter&lt;/code&gt; that wraps Mummy's normal routing with metadata: summaries, tags, and response schemas generated via &lt;code&gt;schemaOf&lt;/code&gt;. Every one of the 12 bundled examples now serves a live &lt;code&gt;/openapi.json&lt;/code&gt; and an interactive &lt;code&gt;/docs&lt;/code&gt; page, generated from the same route definitions that handle requests — no separate spec file to maintain.&lt;/p&gt;
&lt;p&gt;From there I added three more pieces that came up naturally once the schema layer existed:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Typed path params&lt;/strong&gt; (&lt;code&gt;openapi_params.nim&lt;/code&gt;) — &lt;code&gt;pathParam[T](request, &quot;id&quot;)&lt;/code&gt; pulls a path segment straight out as an &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;string&lt;/code&gt;, or whatever type you declare, instead of manually parsing strings on every handler.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Request body validation&lt;/strong&gt; (&lt;code&gt;openapi_validation.nim&lt;/code&gt;) — &lt;code&gt;parseValidatedBody[T]&lt;/code&gt; checks an incoming JSON body against the same schema that &lt;code&gt;schemaOf&lt;/code&gt; generated for your docs, so the validation and the documentation can't drift apart.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Composable middleware&lt;/strong&gt; (&lt;code&gt;openapi_middleware.nim&lt;/code&gt;) — a &lt;code&gt;Middleware&lt;/code&gt; type and a &lt;code&gt;use()&lt;/code&gt; method on the router, with logging and bearer-auth middleware included out of the box.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Every feature was compiled and exercised with real HTTP requests, not just &lt;code&gt;nim check&lt;/code&gt;, before I called it done — including converting a wildcard WebSocket route to a named path param and confirming it fixed a small latent bug where the old code read the raw request URI (query string and all) instead of the decoded path.&lt;/p&gt;
&lt;h3 id=&quot;what-the-wider-nim-community-s-experience-with-mummy-adds&quot;&gt;What the Wider Nim Community's Experience With Mummy Adds&lt;/h3&gt;
&lt;p&gt;Reading through discussion around Mummy on the Nim mailing list and forum was useful context while building this. One recurring theme: Mummy's design intentionally keeps some things out of scope in the name of simplicity. A developer comparing thread-per-request servers noted that Mummy's multipart handling, while present, buffers the entire upload into memory rather than streaming it — a deliberate trade-off for simplicity that matters if you're building something like a file-upload service, and pointed to alternatives like Guildenstern for cases needing streaming multipart support.&lt;/p&gt;
&lt;p&gt;That trade-off is directly relevant to schema-driven validation work: &lt;code&gt;parseValidatedBody[T]&lt;/code&gt; inherits the same &quot;load it all, then check it&quot; model. For typical JSON APIs that's a non-issue, but it's a useful thing to know going in if you're planning a Mummy-based service that also needs large file uploads — you may want to keep that path outside the validated-body flow rather than fight the framework's grain.&lt;/p&gt;
&lt;p&gt;It's also worth knowing you're not alone in wanting typed, schema-aware APIs on Mummy — a separate project, Sarcophagus, tackles a similar problem from a different angle: typed request/response encoding across JSON, CBOR, and MessagePack, plus its own Swagger/OpenAPI generation and OAuth2 helpers. Different design choices, same underlying itch in the ecosystem — which suggests this is a real gap worth filling rather than a one-off preference of mine.&lt;/p&gt;
&lt;h3 id=&quot;putting-it-to-use&quot;&gt;Putting It to Use&lt;/h3&gt;
&lt;p&gt;To validate the fork beyond the bundled examples, I built a small Todo API demo using the typed params, validation, and middleware together, and I'm deploying it live on Render as a working reference — a REST API with real request validation and generated docs, running on a threaded model with no &lt;code&gt;async&lt;/code&gt; in sight.&lt;/p&gt;
&lt;h3 id=&quot;where-this-goes-next&quot;&gt;Where This Goes Next&lt;/h3&gt;
&lt;p&gt;The fork is usable today for anyone building JSON APIs on Mummy who wants documentation and validation that can't silently drift from the actual routes. If you're working in the Nim web space and hit the same &quot;no schema, no docs&quot; wall, I'd genuinely like to hear how you're solving it — feel free to reach out.&lt;/p&gt;
</description>
<category>Articles</category>
<guid isPermaLink="true">https://coderlegion.com/27091/adding-openapi-support-to-mummy-a-nim-http-framework</guid>
<pubDate>Sun, 13 Sep 2026 22:28:03 +0000</pubDate>
</item>
</channel>
</rss>