Network.Wai.UrlMap

wai-extra-3.1.17: Provides some basic WAI handlers and middleware.

Safe Haskell | None
Language | Haskell2010

Network.Wai.UrlMap

Description

This module gives you a way to mount applications under sub-URIs. For example:

    bugsApp, helpdeskApp, apiV1, apiV2, mainApp :: Application

    myApp :: Application
    myApp = mapUrls $
          mount "bugs"     bugsApp
      <|> mount "helpdesk" helpdeskApp
      <|> mount "api"
              (   mount "v1" apiV1
              <|> mount "v2" apiV2
              )
      <|> mountRoot mainApp

Synopsis

- data UrlMap' a
- type UrlMap = UrlMap' Application
- mount' :: ToApplication a => Path -> a -> UrlMap
- mount :: ToApplication a => Text -> a -> UrlMap
- mountRoot :: ToApplication a => a -> UrlMap
- mapUrls :: UrlMap -> Application

# Documentation

data UrlMap' a #

#### Instances

Instances details

Alternative UrlMap' # |
Instance details Defined in Network.Wai.UrlMap Methods empty :: UrlMap' a # (<|>) :: UrlMap' a -> UrlMap' a -> UrlMap' a # some :: UrlMap' a -> UrlMap' [a] # many :: UrlMap' a -> UrlMap' [a] #
Applicative UrlMap' # |
Instance details Defined in Network.Wai.UrlMap Methods pure :: a -> UrlMap' a # (<*>) :: UrlMap' (a -> b) -> UrlMap' a -> UrlMap' b # liftA2 :: (a -> b -> c) -> UrlMap' a -> UrlMap' b -> UrlMap' c # (*>) :: UrlMap' a -> UrlMap' b -> UrlMap' b # (<*) :: UrlMap' a -> UrlMap' b -> UrlMap' a #
Functor UrlMap' # |
Instance details Defined in Network.Wai.UrlMap Methods fmap :: (a -> b) -> UrlMap' a -> UrlMap' b # (<$) :: a -> UrlMap' b -> UrlMap' a #

type UrlMap = UrlMap' Application #

mount' :: ToApplication a => Path -> a -> UrlMap #

Mount an application under a given path. The ToApplication typeclass gives you the option to pass either an `Application` or an `UrlMap` as the second argument.

mount :: ToApplication a => Text -> a -> UrlMap #

A convenience function like mount', but for mounting things under a single path segment.

mountRoot :: ToApplication a => a -> UrlMap #

Mount something at the root. Use this for the last application in the block, to avoid 500 errors from none of the applications matching.

mapUrls :: UrlMap -> Application #