Skip to content

Conversation

@Kleidukos
Copy link
Owner

No description provided.

@Kleidukos
Copy link
Owner Author

@TristanCacqueray I'm having a hard finding an example of "usual" Servant setup to showcase how integrating with servant-effectful would look like. I'm blocked on the place that the natural transform would take. Do you have any idea how to showcase "this is what this usually looks like and this is what it will look like"?

@TristanCacqueray
Copy link
Contributor

@Kleidukos I'm not entirely sure what you mean by natural transform, but I would show a named route api implemented with a reader and logger effects. Then we could demonstrate how to serve it along with a basic health-check middleware?

@Kleidukos
Copy link
Owner Author

Kleidukos commented Dec 20, 2024

@TristanCacqueray "natural transform" or "nt" is the term used by Servant to talk about the operation that turns your domain monad (custom reader, etc) back to a Handler monad. See https://docs.servant.dev/en/stable/cookbook/using-custom-monad/UsingCustomMonad.html for instance.

For instance, this function runHoogle is used with genericServeTWithContext (https://git.mangoiv.com/mangoiv/modern-hoogle/src/branch/main/src/Hoogle/Modern.hs#L25-L28)

It's roughly the function where you execute your effects: https://github.com/flora-pm/flora-server/blob/development/src/web/FloraWeb/Server.hs#L207-L228 that serveTWithContext accepts

@Kleidukos
Copy link
Owner Author

@TristanCacqueray do you see what I'm talking about?

@TristanCacqueray
Copy link
Contributor

@Kleidukos ok, so what would be the use case to use natural transform when servant-effectful already provides runWarpServerSettingsContext which takes care of it?

@Kleidukos
Copy link
Owner Author

@TristanCacqueray I'm just having a hard time wrapping my mind around the new way to pass the runReader, runResource, runState, etc.

@Kleidukos
Copy link
Owner Author

@TristanCacqueray Just so we are clear, how would you deal with such a thing? https://github.com/flora-pm/flora-server/blob/development/src/web/FloraWeb/Server.hs#L198-L202

@TristanCacqueray
Copy link
Contributor

Ha I see, well we actually use some of the effects before serving the API (e.g. to initialize the db), so we have a bunch of E.runEffect before getting to servant-effectful. Here is how that looks in monocle: https://github.com/change-metrics/monocle/blob/8ffa58d7cc93a16a1c1e530b08de6321c29e2f16/src/Monocle/Main.hs#L180-L202

Though we haven't review this implem since the switch to effectful, so perhaps we are doing some wrong, but I think that's what servant-effectful should provide, just the runWarpServerSettingsContext, and the user will peel the effects needed by their API before hand.

@Kleidukos
Copy link
Owner Author

@alpmestan if you have any insights I'm all ears. :)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants