1

The function getUrlRender is used for converting Route (HandlerSite m) to Text, through the use of Monads. For instance:

routeToText :: MonadHandler m => Route (HandlerSite m) -> m Text
routeToText url = do
  r <- getUrlRender
  return $ r url

getTestR :: Text -> Handler Text
getTestR something = routeToText (TestR something)

But what if I want to pass in a query parameter? Could I do it without dealing directly with Texts? Another question, could I simplify the type declaration of the function routeToText?

I will use these urls to accomplish with a JSON API specification regarding pagination, I've created all the abstraction to work with it but I don't know how to implement a way to put a link like http://example.com/articles?page=2 in a concise way. If there is a even better way to put the link with the query parameter integrating it beautifully with the Aeson library without converting it to Text first, please, let me know.

FtheBuilder
  • 1,410
  • 12
  • 19
  • Relevant question: http://stackoverflow.com/questions/19046988/yesod-using-typesafe-urls-in-ajax-calls – arrowd Apr 22 '16 at 06:18
  • I think you might be best off using [Network.HTTP.Types.URI](https://hackage.haskell.org/package/http-types-0.9/docs/Network-HTTP-Types-URI.html) to generate the query string, then append that to the generated URL. – MaxGabriel Apr 22 '16 at 21:41
  • You could potentially use the `URI` data type in [`Network.URI`](https://hackage.haskell.org/package/network-uri-2.6.1.0/docs/Network-URI.html) to avoid manipulating `Text`s. – MaxGabriel Apr 22 '16 at 21:44

0 Answers0