A Tiny Nim Microservice, Three... Note

A Tiny Nim Microservice, Three Real Bugs, and What They Taught Me About My Own Mummy Fork

The author built a POST /api/contact endpoint for their portfolio website to handle messages. They used their Mummy fork, which includes OpenAPI schema generation and typed validation. The endpoint accepts name, email, and message, performing validation on presence, type, length, and email format. Errors during validation return a 400 response, while potential send failures result in a generic 500. Additional middleware includes CORS handling, an in-memory rate limiter, and logging. Initially planned for SMTP, the service was switched to Resend's REST API due to Render's free tier limitations on outbound SMTP ports. Three unexpected bugs arose: a type mismatch due to aliased std/httpcore imports, a gcsafe compiler issue with a logically immutable global variable, and the unregistered OPTIONS route preventing middleware execution for preflight requests. Each bug provided valuable insights into the fork's internal workings, Nim's module system, and thread-safe programming. The author emphasizes that these issues are specific to the intersection of Nim's features and the Mummy framework. The full implementation details and deployment scripts are available in the project's repository.