I'm writing a REST API for a resource in Yesod. I have a POST method that should try to create the given resource and if successful return 201 and the ID of the newly created resource. E.g.,
postResourceR :: Handler String
postResourceR = do
id <- runDB $ insert Resource
sendResponseStatus status201 id -- DOES NOT COMPILE
Here's the error I get, which is plain enough:
No instance for (ToTypedContent (Key Resource))
arising from use of 'sendResponseStatus'
I know I want something of the ToTypedContent
, but I can't find any way to get that from a Key
in Database.Persist.Class. Any help would be greatly appreciated.
EDIT:
Here's the definition of the actual resource:
Notification
title Text
content Text
icon Text Maybe
action Text Maybe
created UTCTime
updated UTCTime
deriving Show
Presuming you're using a SQL backend, you can use fromSqlKey. More generally you can use toBackendKey.