summaryrefslogtreecommitdiff
path: root/CLAUDE.md
blob: efbbe42c2ddb3bbb2ec47081da5bbd223e4f9564 (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
30
31
32
33
34
35
36
37
# OCaml SSR React APP on Eio

This app is a WIP to implement a blog as a React webapp using Ocaml, mlx for JSX, Piaf for HTTP handling, Caqti to handle database queries, using Eio across the app for async.


## Build the app 
To compile the app and see if the code is correct do:
`dune clean && dune build`


## Things to take into account

### Ocaml Routes library

#### The `@-->` Operator

The `@-->` operator is from the `routes` library and is used to bind route patterns to handler functions.

##### Example:
```ocaml
`GET, (s "posts" /? nil) @--> Handler.get_posts
```

##### Breaking it down:
- `s "posts"` - matches the string "posts" in the URL path
- `/?` - path concatenation operator 
- `nil` - end of path (no more segments)
- `@-->` - "maps to" operator that binds the route to the handler

So `(s "posts" /? nil) @--> Handler.get_posts` means "the route `/posts` maps to the `Handler.get_posts` function".

##### Other common operators in the routes library:
- `/:` for path parameters (e.g., `s "user" /: int /? nil` matches `/user/123`)
- `//` for wildcard paths
- `<$>` for transforming matched values

It's a DSL (domain-specific language) for expressing routes in a concise, type-safe way.