Hi,
I'm working on a resource with different representations: HTML, PNG image, JSON, Text.
I have considered to create seperate resources but in fact, the representations are really representations of one thing and they all share the same parameters and computations.
The PNG image is created on-demand as a file. So I have
getNn2GSR :: Handler TypedContent
getNn2GSR = selectRep $ do
provideRep $ defaultLayout $ ...
provideRep $ sendFile "image/png" "test.png"
That doesn't work because Haskell cannot infer the type of (sendFile ...). It says "Ambigious type variable [..] prevents the constraint '(HasContentType a0)' from beeing solved."
After trial and error I found that this at least compiles:
provideRep $ (sendFile "image/png" "test.png" :: Handler RepPlain)
But selectRep does not select this representation for a 'Accept: image/*' header.
1. Are there better ways to solve this problem?
E.g. change the route to
/my/service#Text MyServiceR GET
where #Text is "", ".html", ".png", ... and
when (format == ".png") $ sendFile ...
or better use different routes?
2. ... or do I have to define a new RepImage and define all required instances?
3. ... or can it solved even simpler?