0 | module HTTP.API.Server.Method
2 | import HTTP.API.Server.Interface
6 | checkResponseTypes : All (EncodeVia t) ts -> Request -> Handler ()
7 | checkResponseTypes a r =
8 | let mts := forget $
mapProperty (\x => mediaType @{x}) a
9 | in case any (acceptsMedia r.headers) mts of
14 | "I provide: \{show mts}; Request accepts: \{show $ accept r.headers}"
15 | unsupportedMediaType415
18 | Serve ReqMethod where
21 | OutTypes m = MethodResults m
23 | Constraint (M _ _ _ Nothing0) = ()
24 | Constraint (M _ _ fs $
Just0 t) = All (EncodeVia t) fs
26 | outs (M _ _ _ Nothing0) = []
27 | outs (M _ _ _ $
Just0 t) = [t]
29 | canHandle (M m _ _ _) r = m == r.method
30 | fromRequest m r = pure []
31 | adjResponse (M _ s _ Nothing0) _ req resp = pure (setStatus s resp)
32 | adjResponse (M _ s _ $
Just0 _) [v] req resp = do
33 | checkResponseTypes con req
34 | pure $
encodeBody s v req.headers con resp