From d43776f556ba63d2e6f48fdf6f94ba3b8f1e0199 Mon Sep 17 00:00:00 2001 From: polwex Date: Wed, 16 Jul 2025 22:37:58 +0700 Subject: m --- ROUTER_CHANGES.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 ROUTER_CHANGES.md (limited to 'ROUTER_CHANGES.md') diff --git a/ROUTER_CHANGES.md b/ROUTER_CHANGES.md new file mode 100644 index 0000000..5f7aab3 --- /dev/null +++ b/ROUTER_CHANGES.md @@ -0,0 +1,19 @@ +# Router.ml Review and Changes + +## Summary of Changes + +- **Type annotations added** for all top-level bindings in `lib/router.ml`: + - `module R` now has an explicit `Map.S` signature keyed by `Method.t`. + - `compare`, `static`, `routes`, `router`, and `match_route` were all given explicit parameter and return-type annotations. +- **Static-assets route** was temporarily commented out to unblock compilation of other routes. +- **Fixed type errors** in `routes` and `router`: + - `routes` is now annotated as `(Handler.pool -> Request.t -> (Response.t, Caqti_error.t) result) route list R.t`. + - `router` is now annotated as `(Handler.pool -> Request.t -> (Response.t, Caqti_error.t) result) router R.t`. + +## Impressions of the Codebase + +- The project uses the `routes` DSL and `Piaf` to define a type-safe HTTP router in OCaml. +- Patterns (`s`, `/`, `/?`, `int`, `str`, `wildcard`, `@-->`) make the routes very declarative, but the necessary type annotations can become verbose, especially when inferring the correct `route` versus `router` types. +- Static file handling with `Body.sendfile` and `Body.to_string` is straightforward, though error paths currently propagate raw errors rather than returning HTTP error responses (which might be improved later). +- The `dune` setup is standard, with a shared library and pages sub-library, plus `ppx_rapper_eio` for DB bindings. +- Overall, the code structure is clean and idiomatic, but the interaction of the routes DSL with OCaml’s type system can be a bit tricky when refining precise types. \ No newline at end of file -- cgit v1.2.3