Return inserted object from POST when Prefer: return=representation

Fixes #27
Fixes #159
This commit is contained in:
Joe Nelson
2015-03-01 21:42:05 -08:00
parent 11e5918690
commit 5be0b5d5ae
3 changed files with 13 additions and 2 deletions
+2 -1
View File
@@ -102,6 +102,7 @@ app reqBody req =
handleJsonObj reqBody $ \obj -> do
let qt = QualifiedTable schema (cs table)
query = insertInto qt (map cs $ keys obj) (elems obj)
echoRequested = lookup "Prefer" hdrs == Just "return=representation"
row <- H.maybeEx query
let (Identity insertedJson) = fromMaybe (Identity "{}" :: Identity Text) row
Just inserted = decode (cs insertedJson) :: Maybe Object
@@ -116,7 +117,7 @@ app reqBody req =
return $ responseLBS status201
[ jsonH
, (hLocation, "/" <> cs table <> "?" <> cs params)
] ""
] $ if echoRequested then cs insertedJson else ""
([table], "PUT") ->
handleJsonObj reqBody $ \obj -> do