servant-router-0.7.1: Servant router for non-server applications.

Safe HaskellNone
LanguageHaskell2010

Servant.Router

Synopsis

Documentation

data View Source

Router terminator. The HasRouter instance for View finalizes the router.

Example:

type MyApi = "books" :> Capture "bookId" Int :> View

Instances

HasRouter * View Source 
type RouteT * View m a = m a Source 

data Location Source

Location is used to split the path and query of a URI into components.

Constructors

Location 

Fields

locPath :: [Text]
 
locQuery :: Query
 

data RoutingError Source

When routing, the router may fail to match a location. Either this is an unrecoverable failure, such as failing to parse a query parameter, or it is recoverable by trying another path.

Constructors

Fail 
FailFatal 

data Router m a where Source

A Router contains the information necessary to execute a handler.

Constructors

RChoice :: Router m a -> Router m a -> Router m a 
RCapture :: FromHttpApiData x => (x -> Router m a) -> Router m a 
RQueryParam :: (FromHttpApiData x, KnownSymbol sym) => Proxy sym -> (Maybe x -> Router m a) -> Router m a 
RQueryParams :: (FromHttpApiData x, KnownSymbol sym) => Proxy sym -> ([x] -> Router m a) -> Router m a 
RQueryFlag :: KnownSymbol sym => Proxy sym -> (Bool -> Router m a) -> Router m a 
RPath :: KnownSymbol sym => Proxy sym -> Router m a -> Router m a 
RPage :: m a -> Router m a 

class HasRouter layout where Source

This is similar to the HasServer class from servant-server. It is the class responsible for making API combinators routable. RuoteT is used to build up the handler types. Router is returned, to be interpretted by routeLoc.

Associated Types

type RouteT layout m a :: * Source

Methods

route :: Proxy layout -> Proxy m -> Proxy a -> RouteT layout m a -> Router m a Source

Instances

HasRouter * View Source 
(HasRouter * x, HasRouter * y) => HasRouter * ((:<|>) x y) Source 
(HasRouter k sublayout, KnownSymbol sym) => HasRouter * ((:>) * k (QueryFlag sym) sublayout) Source 
(HasRouter k sublayout, FromHttpApiData x, KnownSymbol sym) => HasRouter * ((:>) * k (QueryParams * sym x) sublayout) Source 
(HasRouter k sublayout, FromHttpApiData x, KnownSymbol sym) => HasRouter * ((:>) * k (QueryParam * sym x) sublayout) Source 
(HasRouter k sublayout, FromHttpApiData x) => HasRouter * ((:>) * k (Capture * sym x) sublayout) Source 
(HasRouter k sublayout, KnownSymbol path) => HasRouter * ((:>) Symbol k path sublayout) Source 

runRoute :: forall layout m a. (HasRouter layout, MonadError RoutingError m) => String -> Proxy layout -> RouteT layout m a -> m a Source

Use a handler to route a location, represented as a String. All handlers must, in the end, return m a. routeLoc will choose a route and return its result.

routeLoc :: MonadError RoutingError m => Location -> Router m a -> m a Source

Use a computed Router to route a Location.