theam / aws-lambda-haskell-runtime

⚡Haskell runtime for AWS Lambda
https://theam.github.io/aws-lambda-haskell-runtime/
Other
270 stars 48 forks source link

Clarification in docs w.r.t setting headers in response #49

Open hazelweakly opened 5 years ago

hazelweakly commented 5 years ago

While screwing around with the library, I got the clever idea to try returning html directly from an aws function rather than JSON. In node this is easy to do by just setting the response header ContentType to html.

However, this runtime seems to require that ToJSON be implemented for the response type, but as far as I can see, the headers are supposed to be of type [(HeaderName, ByteString)] as specified in the documentation. Of course, bytestring has no ToJSON instance (neither does HeaderName) so GHC rightfully throws a fit.

Is there something I'm missing regarding setting headers for the response? Or with the (albeit unusual) usecase of spitting out HTML directly from a function?

hazelweakly commented 5 years ago

So, my confusion regarding this ended up being due to a misunderstanding of how things worked between aws, aws lambda, and haskell specific things. I'll summarize the things I've learned in the interim below (and if you'd like I can open up a PR for docs too):

Due to not being very familiar with lambdas and aws in general, it was sometimes hard to know what was haskell specific and what was lambda specific. I think it would've been helpful to have the getting started tutorial go all the way to a hello world example, even if just linking to the aws docs for the next steps.

To my surprise, creating a default settings route in the gateway was sufficient because of the json shape I return in my response. I didn't need to screw with the gateway to make it return html ¯\_(ツ)_/¯ so that was nice.