Build a REST API in Go with named URL parameters like /user/:id without pulling in a heavy web framework.
Serve static files from a Go web server alongside API routes using HttpRouter's built-in file serving.
Add automatic 405 Method Not Allowed responses and OPTIONS handling to a Go API for REST and CORS compliance.
Replace Go's standard library router to get clean URL matching, trailing-slash redirects, and automatic path-mistake fixes.
HttpRouter is a lightweight HTTP request router for Go, a programming language commonly used to build web services. A router, also called a multiplexer or mux for short, is the part of a web server that decides which piece of code should handle each incoming request based on the URL and the request method like GET or POST. HttpRouter exists because Go's built-in standard router does not support variables in URL paths and does not distinguish between request methods, which is awkward when building modern web APIs. The library is built around a compact tree structure called a radix tree, which groups routes that share a common prefix. This lets the router quickly find a match even when there are many routes or long URL paths, and matching is designed to allocate almost no extra memory. A request can only match exactly one registered route, so there are no ambiguous overlaps. URL paths can contain named placeholders like :name to capture a single segment, or catch-all placeholders like *filepath to capture everything after a point in the path. Beyond raw matching, the README highlights quality-of-life behavior: it can automatically redirect requests when a trailing slash is wrong, fix common path mistakes like wrong casing or stray slashes, serve static files, and recover from crashes inside a handler through a panic handler. It also has built-in support for OPTIONS requests and 405 Method Not Allowed responses, which makes it a natural fit for hierarchical REST-style APIs. You would reach for HttpRouter when writing a Go web service or API and want predictable, fast routing without pulling in a full web framework. The full README is longer than what was provided.
← julienschmidt on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.