我如何用 Yesod 中的密钥值进行响应?

How do I respond with the value of a Key in Yesod?

我正在为 Yesod 中的资源编写 REST API。我有一个 POST 方法应该尝试创建给定的资源,如果成功 return 201 和新创建资源的 ID。例如,

postResourceR :: Handler String
postResourceR = do
  id <- runDB $ insert Resource
  sendResponseStatus status201 id -- DOES NOT COMPILE

这是我得到的错误,很简单:

No instance for (ToTypedContent (Key Resource))
  arising from use of 'sendResponseStatus'

我知道我想要 ToTypedContent 的东西,但我找不到任何方法从 Database.Persist.Class 中的 Key 得到它。任何帮助将不胜感激。

编辑:

这里是实际资源的定义:

Notification
    title Text
    content Text
    icon Text Maybe
    action Text Maybe 
    created UTCTime
    updated UTCTime
    deriving Show

假设您使用的是 SQL 后端,您可以使用 fromSqlKey. More generally you can use toBackendKey.