Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dynamic BaseUrl #101

Open
imalsogreg opened this issue Aug 22, 2020 · 2 comments
Open

Remove dynamic BaseUrl #101

imalsogreg opened this issue Aug 22, 2020 · 2 comments

Comments

@imalsogreg
Copy link
Owner

The servant-reflex generated client functions accept a Dynamic BaseUrl. I believe noone uses this - BaseUrl will be constant for every normal use-case, and for any odd instance where we want to modify it at runtime, that can be achieved by rebuilding the client functions within widgetHold.

If you do make use of the dynamic BaseUrl, and want me to keep it, please drop a message here. Otherwise I'll remove it, because I believe it only makes the use of this library more confusing.

@ibizaman
Copy link

ibizaman commented Aug 30, 2020

Not sure my opinion is worth anything as I just began using servant-reflex. But to the contrary, I thought it was a cool idea because it would be easy to allow the user to setup the backend address in a widget. Not sure how much I will use it this way in practice though.

If you end up removing it, can you show an example of how to rebuild the client functions?

@imalsogreg
Copy link
Owner Author

Thanks for the feedback! Your opinion is worth a ton, since I don't want to be twiddling the API on just my own whims. I'll leave this ticket open for a while and we can see if you or others do end up using the dynamic baseurl.

If I remove it, I'll give more detailed instructions. But for now, the gist of how you would rebuild the client functions is like this:

appMain :: forall t m. (SupportsServantReflex t m) => m ()
appMain = do
  nClicks <- count =<< button "Update Version"

  -- Every time user clicks the button, bump to the next API version
  let baseUrl = ffor nClicks $ \n -> BasePath ("/api/" <> pack (show n))

  -- Rebuild this part of the UI when BaseUrl changes
  dyn_ $ ffor baseUrl $ \u -> do

    queryCatchphraseDatabase = ServantReflex.client (Proxy @MyAPI) (Proxy @m) (Proxy @()) u
    userID<- textInput def
    fetch <- button "Submit"
    userCatchphrase <- queryCatchphraseDatabase (tagPromptlyDyn userID fetch) fetch
    display userCatchphrase

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

No branches or pull requests

2 participants