fn icon indicating copy to clipboard operation
fn copied to clipboard

Add a `FromParam` instance for String

Open emhoracek opened this issue 7 years ago • 2 comments

FromParam has instances for some common types, but it doesn't have an instance for String. That's not such a big deal, because usually it's nicer to use Text. But since a lot of functions from Prelude still use String, it makes sense to let users have String params as well.

Adding a String instance will let people write a route like this:

route ctxt [ path "hello" // param "name" ==> helloHandler ]

and a handler like this:

helloHandler :: Ctxt -> String -> IO (Maybe Response)
helloHandler ctxt name = 
  let helloMessage = T.pack ("Hello " ++ name) in 
    okText helloMessage

And when you went to "/hello?name=Suzy", you would see "Hello Suzy".

Right now, you would get an error that there's no FromParam instance for String.

emhoracek avatar Aug 03 '17 18:08 emhoracek

Hi! I came across this project through the hacktoberfest label. I was wondering if I could take this?

arbuztw avatar Oct 01 '17 07:10 arbuztw

@arbuztw go for it! I forgot to mention above -- you'll also want to add a test to fn/test/Spec. Let me know if you have any questions.

emhoracek avatar Oct 01 '17 12:10 emhoracek