Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- data PathInfo
Documentation
PathInfo
provides handlers access to the path segments from the
request, without the domain name or query parameters. We re-generate
this from the rawPathInfo via
Network.HTTP.Types.decodePathSegments
because Servant removes all
fields from the pathInfo
field of a request as part of routing the
request to the appropriate handler.
Example:
import Data.ByteString (ByteString) import Control.Monad.IO.Class (liftIO) import Servant import ServantExtras.RawPathInfo type MyAPI = "merlin" :> "my-path-info-endpoint" :> PathInfo :> Get '[JSON] NoContent myServer :: Server MyAPI myServer = pathInfoEndpointHandler where pathInfoEndpointHandler :: [Text] -> Handler NoContent pathInfoEndpointHandler pInfo = do case (elem "merlin" pInfo) of False -> do liftIO $ print "This example has a bug!" throwError err400 { errBody = "Patches accepted!" } True -> do liftIO $ print "Hopefully this demonstrates how path info works." pure NoContent