A Clojure/ClojureScript library for bidirectional URI routing, treating routes as data structures.
bidi is a bidirectional URI routing library for Clojure and ClojureScript that treats routes as data structures. It solves the problem of hardcoded URIs in web applications by enabling both matching incoming requests to handlers and generating URIs from handlers, which is crucial for building maintainable RESTful APIs with proper HATEOAS links.
Clojure and ClojureScript developers building web applications, especially those using Ring-compatible servers (like Jetty or http-kit) and needing robust URI management for RESTful APIs or SPAs.
Developers choose bidi for its data-driven approach, bidirectional routing capabilities, and clean separation of routing from request handling, which reduces coupling and improves code maintainability compared to macro-based alternatives.
Bidirectional URI routing
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Routes are defined as plain Clojure data structures like vectors and maps, allowing easy generation, transformation, and introspection, as shown in the REPL examples for dynamic route manipulation.
Supports both matching URIs to handlers and generating URIs from handlers, which is essential for building RESTful APIs with HATEOAS links and avoiding hardcoded URIs, as emphasized in the philosophy.
Works seamlessly in both Clojure and ClojureScript environments, enabling consistent routing across server and client-side code, highlighted in the library's cross-platform support in the comparison table.
Built on Clojure protocols, allowing users to define custom pattern and match types, making it adaptable to complex routing needs beyond built-in features, as detailed in the extensibility section.
The library deliberately avoids terse forms, leading to more verbose route definitions compared to macro-based DSLs like Compojure, which can increase code bulk and reduce readability for simple routes.
Uncompiled routes have higher overhead and are slower than alternatives, as shown in performance tests where uncompiled bidi lagged behind Compojure, though compilation helps mitigate this.
Since bidi focuses only on routing, developers must integrate it with separate libraries for middleware and request handling, such as Ring, adding to initial setup and potential dependency management issues.