mirror of
https://github.com/monadicsystems/okapi.git
synced 2024-11-22 00:51:34 +03:00
Add any function for handling all HTTP methods with the same handler
This commit is contained in:
parent
13291db5a5
commit
13c22c26ea
@ -329,6 +329,18 @@ endpoint ::
|
||||
endpoint stdMethod transformation handler =
|
||||
route @a $ method @env @(r :-> a) stdMethod transformation handler
|
||||
|
||||
any ::
|
||||
forall env (r :: [Type]).
|
||||
(Typeable.Typeable r) =>
|
||||
(env Natural.~> IO) ->
|
||||
Handler r env ->
|
||||
Node r
|
||||
any transformation handler =
|
||||
choice
|
||||
[ Method @env @r stdMethod transformation handler
|
||||
| stdMethod <- [minBound ..]
|
||||
]
|
||||
|
||||
data HList (l :: [Type]) where
|
||||
HNil :: HList '[]
|
||||
HCons :: e -> HList l -> HList (e ': l)
|
||||
|
@ -167,13 +167,14 @@ makeResponder ::
|
||||
forall (status :: Natural.Natural) (headerKeys :: [Exts.Symbol]) (contentType :: Type) (resultType :: Type).
|
||||
(Nat.KnownNat status, ContentType contentType, ToContentType contentType resultType, Typeable.Typeable headerKeys, Typeable.Typeable resultType) =>
|
||||
(Headers headerKeys -> resultType -> Wai.Response)
|
||||
makeResponder _ result =
|
||||
makeResponder headerMap result =
|
||||
let status = natToStatus $ Nat.natVal @status Typeable.Proxy
|
||||
contentType = toContentType @contentType @resultType result
|
||||
bodyType = contentTypeBody @contentType contentType
|
||||
name = contentTypeName @contentType
|
||||
headers = toWaiResponseHeaders headerMap
|
||||
in case bodyType of
|
||||
BodyBytes bytes -> Wai.responseLBS status [] bytes
|
||||
BodyBuilder builder -> Wai.responseBuilder status [] builder
|
||||
BodyStream stream -> Wai.responseStream status [] stream
|
||||
BodyFile path part -> Wai.responseFile status [] path part
|
||||
BodyBytes bytes -> Wai.responseLBS status headers bytes
|
||||
BodyBuilder builder -> Wai.responseBuilder status headers builder
|
||||
BodyStream stream -> Wai.responseStream status headers stream
|
||||
BodyFile path part -> Wai.responseFile status headers path part
|
||||
|
Loading…
Reference in New Issue
Block a user