summaryrefslogtreecommitdiff
path: root/ROUTER_CHANGES.md
blob: b82f68718bd4e4aec4f2f931f9fc28f30cc429f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# 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.

## Dune shenanigans
deleted this but might come in handy later
 (rule
 (target styles.css)
 (deps
  input.css
  tailwind.sh)
 (action
  (bash "sh %{workspace_root}/tailwind.sh")))