In the Yesod ecosystem, what is the best way to urlencode some text?

I would like to encode Text code (for example, replace each space with% 20, etc.). I found the "HTTP" Network.HTTP.Base.urlEncode and could use this, but I am wondering if there is anything else that is commonly used in the Yesod ecosystem.

+6
source share
2 answers

Unfortunately, due to the complexity of URL escaping, the real answer is "it depends." There are slightly different rules for percent coding path segments and query strings, for example.

I do not know exactly what you are trying to code, but I recommend sticking with the http-types package. One place to start would be urlEncode , although there are many other features in this package (such as encodePathSegments mentioned by @jamshidh) that are worth a look.

+6
source

As I understand it, URI encoding is complicated. However, for my simple case, I was able to get through with the uri-encode package.

All I needed was:

 encode :: String -> String 

As you can imagine, all it does is take a string and return you a version encoded in a URI.

+1
source

All Articles