0 | module HTTP.API.Server.Method
 1 |
 2 | import HTTP.API.Server.Interface
 3 |
 4 | %default total
 5 |
 6 | parameters {auto loc : HTTPLocal}
 7 |   checkResponseTypes : All (EncodeVia t) ts -> Request -> Handler ()
 8 |   checkResponseTypes a r =
 9 |    let mts := forget $ mapProperty (\x => mediaType @{x}) a
10 |     in case any (acceptsMedia r.headers) mts of
11 |          True => pure ()
12 |          False =>
13 |           let msg := myMediaTypeNotAccepted (commaSepS mts) (commaSepS $ accept r.headers)
14 |            in throw $ requestErrDetails msg unsupportedMediaType415
15 |
16 |   public export
17 |   Serve ReqMethod where
18 |     InTypes m = []
19 |
20 |     OutTypes m = MethodResults m
21 |
22 |     Constraint (M _ _ _ Nothing0)   = ()
23 |     Constraint (M _ _ fs $ Just0 t) = All (EncodeVia t) fs
24 |
25 |     outs (M _ _ _ Nothing0)  = []
26 |     outs (M _ _ _ $ Just0 t) = [t]
27 |
28 |     canHandle (M m _ _ _) r = m == r.method
29 |     fromRequest m r = pure []
30 |     adjResponse (M _ s _ Nothing0)  _   req resp = pure (setStatus s resp)
31 |     adjResponse (M _ s _ $ Just0 _) [v] req resp = do
32 |       checkResponseTypes con req
33 |       pure $ encodeBody s v req.headers con resp
34 |