Introduce new 'Prefer' header, params=single-object (#739)

This commit is contained in:
dsimunic
2016-11-20 14:14:39 -08:00
committed by Joe Nelson
parent 4df853eff9
commit ae40641963
8 changed files with 46 additions and 8 deletions
+4
View File
@@ -96,6 +96,8 @@ data ApiRequest = ApiRequest {
, iPreferRepresentation :: PreferRepresentation
-- | If client wants first row as raw object
, iPreferSingular :: Bool
-- | Pass all parameters as a single json object to a stored procedure
, iPreferSingleObjectParameter :: Bool
-- | Whether the client wants a result count (slower)
, iPreferCount :: Bool
-- | Filters on the result ("id", "eq.10")
@@ -172,6 +174,7 @@ userApiRequest schema req reqBody =
, iPayload = relevantPayload
, iPreferRepresentation = representation
, iPreferSingular = singular
, iPreferSingleObjectParameter = singleObject
, iPreferCount = not singular && hasPrefer "count=exact"
, iFilters = [ (toS k, toS $ fromJust v) | (k,v) <- qParams, isJust v, k /= "select", not (endingIn ["order", "limit", "offset"] k) ]
, iSelect = toS $ fromMaybe "*" $ fromMaybe (Just "*") $ lookup "select" qParams
@@ -197,6 +200,7 @@ userApiRequest schema req reqBody =
split :: BS.ByteString -> [Text]
split = map T.strip . T.split (==',') . toS
singular = hasPrefer "plurality=singular"
singleObject = hasPrefer "params=single-object"
representation
| hasPrefer "return=representation" = Full
| hasPrefer "return=minimal" = None