1

I want to create a simple HTML site that contains even simpler form with only one Submit button. In order to achieve that I created the following Servant API:

type ClientAPI = 
    "prices" :> Get '[HTML] (Html ()) -- returns HTML UI to the user
    :<|> "updatePrices" :> Post '[HTML] (Html ()) -- handles a recalc request

My goal is to redirect user to "prices" site after completing the "updatePrices" procedure. In order to do this I return "prices" view at the end of "updatePrices" handler:

updatePricesView :: Handler (Html ())
updatePricesView = do
    -- do the required logic here
    pricesView -- return the view for "prices" endpoint

This works almost ok. The only drawback is that the address in my browser is set to "/updatePrices" instead of "/prices". As a result, if I hit F5, the whole procedure gets executed once again, which is a bit counterintuitive.

This actually makes me think: how to handle a form properly with Servant ? In other languages I typically implement this as a redirect to the desired site, but can't see anything like this here.

LA.27
  • 1,888
  • 19
  • 35
  • Yeah, I've seen it, but since it says it was a hacky way of doing things I was wondering if there's a better solution. – LA.27 Dec 24 '19 at 01:08

0 Answers0