Update example to redirect within NamedRoutes
This commit is contained in:
parent
a3efe4163d
commit
0f82519899
2 changed files with 6 additions and 2 deletions
|
@ -84,8 +84,9 @@ server = (helloH :<|> postGreetH :<|> deleteGreetH :<|> otherRoutes) :<|> redire
|
|||
RedirectOf (Proxy @("hello" :> Capture "name" Text :> QueryParam "capital" Bool :> Get '[JSON] Greet))
|
||||
(\buildPath -> buildPath "Nicolas" (Just True))
|
||||
|
||||
-- Fail in any other case
|
||||
redirect _ = throwError err500
|
||||
redirect _ = pure $
|
||||
RedirectOf (Proxy @("bye" :> Capture "name" Text :> Get '[JSON] Text))
|
||||
(\buildPath -> buildPath "Gaël")
|
||||
|
||||
-- Turn the server into a WAI app. 'serve' is provided by servant,
|
||||
-- more precisely by the Servant.Server module.
|
||||
|
|
|
@ -60,6 +60,8 @@ import Servant.API.Capture
|
|||
import Servant.API.Fragment
|
||||
import Servant.API.Header
|
||||
(Header)
|
||||
import Servant.API.NamedRoutes (NamedRoutes)
|
||||
import Servant.API.Generic (ToServantApi)
|
||||
import Servant.API.QueryParam
|
||||
(QueryFlag, QueryParam, QueryParams)
|
||||
import Servant.API.ReqBody
|
||||
|
@ -127,6 +129,7 @@ type family IsElem' a s :: Constraint
|
|||
-- request represented by @a@ matches the endpoints serving @b@ (for the
|
||||
-- latter, use 'IsIn').
|
||||
type family IsElem endpoint api :: Constraint where
|
||||
IsElem endpoint (NamedRoutes rec) = IsElem endpoint (ToServantApi rec)
|
||||
IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)
|
||||
IsElem (e :> sa) (e :> sb) = IsElem sa sb
|
||||
IsElem sa (Header sym x :> sb) = IsElem sa sb
|
||||
|
|
Loading…
Reference in a new issue