Skip to content

Conversation

@boechat107
Copy link
Contributor

@boechat107 boechat107 commented Feb 18, 2025

Context

Proposal

⚠️ API Breaking Changes!

This PR proposes adding one additional partial application for Dream.memory_sessions to make it possible to initialize its state before getting a handler.

(*==== Example 1 ====*)
let () =
  Dream.run
  @@ Dream.logger
  @@ Dream.memory_sessions ()
  @@ fun request -> ...

(*==== Example 2 ====*)
Dream.router [
  (* Note the partial application with unit. *)
  Dream.scope "/admin" [Dream.memory_sessions ()] [
    Dream.get "/" admin_handler;
    Dream.get "/logout" admin_logout_handler;
  ];
]

These changes should make it possible to share the session memory state with multiple routes inside a Dream.scope.

Notes

I tried first to change the function apply (router.ml) and make it generate a unified handler using router and building a route directly, but I realized this function wasn't designed for nested calls since it would return a 404 response when the request doesn't match a route.

boechat107 and others added 3 commits February 15, 2025 12:54
The initialization mechanism should make it possible to share a state among
routes in "Dream.scope".
"Dream.memory_sessions" now requires an initialization call.
@boechat107
Copy link
Contributor Author

I believe the CI failures could be fixed by merging #383.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant