module Servant.API.PathInfo where
import Data.Text (Text)
import Network.HTTP.Types (decodePathSegments)
import Network.Wai
import Servant
import Servant.Server.Internal.Delayed (passToServer)
data PathInfo
instance HasServer api ctx => HasServer (PathInfo :> api) ctx where
type ServerT (PathInfo :> api) m = [Text] -> ServerT api m
hoistServerWithContext :: forall (m :: * -> *) (n :: * -> *).
Proxy (PathInfo :> api)
-> Proxy ctx
-> (forall x. m x -> n x)
-> ServerT (PathInfo :> api) m
-> ServerT (PathInfo :> api) n
hoistServerWithContext Proxy (PathInfo :> api)
_ Proxy ctx
ctx forall x. m x -> n x
nt ServerT (PathInfo :> api) m
server =
forall {k} (api :: k) (context :: [*]) (m :: * -> *) (n :: * -> *).
HasServer api context =>
Proxy api
-> Proxy context
-> (forall x. m x -> n x)
-> ServerT api m
-> ServerT api n
hoistServerWithContext (forall {k} (t :: k). Proxy t
Proxy @api) Proxy ctx
ctx forall x. m x -> n x
nt forall b c a. (b -> c) -> (a -> b) -> a -> c
. ServerT (PathInfo :> api) m
server
route :: forall env.
Proxy (PathInfo :> api)
-> Context ctx
-> Delayed env (Server (PathInfo :> api))
-> Router env
route Proxy (PathInfo :> api)
_ Context ctx
ctx Delayed env (Server (PathInfo :> api))
server =
forall {k} (api :: k) (context :: [*]) env.
HasServer api context =>
Proxy api
-> Context context -> Delayed env (Server api) -> Router env
route (forall {k} (t :: k). Proxy t
Proxy @api) Context ctx
ctx forall a b. (a -> b) -> a -> b
$
Delayed env (Server (PathInfo :> api))
server forall env a b.
Delayed env (a -> b) -> (Request -> a) -> Delayed env b
`passToServer` \Request
req ->
ByteString -> [Text]
decodePathSegments forall a b. (a -> b) -> a -> b
$ Request -> ByteString
rawPathInfo Request
req