summaryrefslogtreecommitdiff
path: root/ROUTER_CHANGES.md
blob: 5f7aab3c01e96b4592eea8a2064220323036538c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.