Skip to content

Require an initialization call for "Dream.memory_sessions" - #385

Merged
Willenbrink merged 3 commits into
camlworks:masterfrom
boechat107:348-scope-middleware
Feb 6, 2026
Merged

Require an initialization call for "Dream.memory_sessions"#385
Willenbrink merged 3 commits into
camlworks:masterfrom
boechat107:348-scope-middleware

Conversation

@boechat107

@boechat107 boechat107 commented Feb 18, 2025

Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor Author

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

boechat107 and others added 3 commits February 6, 2026 15:00
The initialization mechanism should make it possible to share a state among
routes in "Dream.scope".
"Dream.memory_sessions" now requires an initialization call.
@Willenbrink

Copy link
Copy Markdown
Collaborator

Thank you!

@Willenbrink
Willenbrink merged commit d8b02ab into camlworks:master Feb 6, 2026
5 of 8 checks passed
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.

2 participants