servant-match-0.1.1: Standalone implementation of servant’s dispatching mechanism

Safe HaskellNone
LanguageHaskell2010

Servant.Match

Description

servant-match provides a standalone implementation of dispatching a function by matching an URI against a servant API. This can be used to parse the URI into a more structured representation. For example:

data DataView
  = Show
  | Edit
  deriving (Show, Eq)

data View
  = ViewUsers
  | ViewNewUser
  | ViewUser !Text !DataView
  deriving (Show, Eq)

data User = User

type API =
  "users" :> (Get '[JSON] [User] :<|> "new" :> ReqBody '[JSON] User :> Post '[JSON] User) :<|>
  "user" :> Capture "user" Text :>
    (Get '[JSON] User :<|>
     "edit" :> ReqBody '[JSON] User :> Put '[JSON] User)

parser :: MatchT API View
parser =
  (ViewUsers :<|> ViewNewUser) :<|> (u -> ViewUser u Show :<|> ViewUser u Edit)

parseView :: URI -> Maybe View
parseView u = matchURI (Proxy :: Proxy API) parser u

Documentation

matchURI :: Matches api => Proxy api -> MatchT api a -> URI -> Maybe a Source #

class Matches api where Source #

Minimal complete definition

matchLocation

Associated Types

type MatchT api r :: * Source #

Methods

matchLocation :: Proxy api -> MatchT api a -> Location -> Maybe a Source #

Instances

Matches * EmptyAPI Source # 

Associated Types

type MatchT EmptyAPI (api :: EmptyAPI) r :: * Source #

(Matches * a, Matches * b) => Matches * ((:<|>) a b) Source # 

Associated Types

type MatchT ((:<|>) a b) (api :: (:<|>) a b) r :: * Source #

Methods

matchLocation :: Proxy (a :<|> b) api -> MatchT (a :<|> b) api a -> Location -> Maybe a Source #

Matches * sub => Matches * (WithNamedContext name subContext sub) Source # 

Associated Types

type MatchT (WithNamedContext name subContext sub) (api :: WithNamedContext name subContext sub) r :: * Source #

Methods

matchLocation :: Proxy (WithNamedContext name subContext sub) api -> MatchT (WithNamedContext name subContext sub) api a -> Location -> Maybe a Source #

Matches k sub => Matches * ((:>) k * (BasicAuth realm userData) sub) Source # 

Associated Types

type MatchT ((:>) k * (BasicAuth realm userData) sub) (api :: (:>) k * (BasicAuth realm userData) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (BasicAuth realm userData) sub) api -> MatchT ((k :> *) (BasicAuth realm userData) sub) api a -> Location -> Maybe a Source #

Matches k sub => Matches * ((:>) k * Vault sub) Source # 

Associated Types

type MatchT ((:>) k * Vault sub) (api :: (:>) k * Vault sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) Vault sub) api -> MatchT ((k :> *) Vault sub) api a -> Location -> Maybe a Source #

Matches k sub => Matches * ((:>) k * IsSecure sub) Source # 

Associated Types

type MatchT ((:>) k * IsSecure sub) (api :: (:>) k * IsSecure sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) IsSecure sub) api -> MatchT ((k :> *) IsSecure sub) api a -> Location -> Maybe a Source #

Matches k sub => Matches * ((:>) k * RemoteHost sub) Source # 

Associated Types

type MatchT ((:>) k * RemoteHost sub) (api :: (:>) k * RemoteHost sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) RemoteHost sub) api -> MatchT ((k :> *) RemoteHost sub) api a -> Location -> Maybe a Source #

Matches k1 sub => Matches * ((:>) k1 * (ReqBody k contentTypes a) sub) Source # 

Associated Types

type MatchT ((:>) k1 * (ReqBody k contentTypes a) sub) (api :: (:>) k1 * (ReqBody k contentTypes a) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k1 :> *) (ReqBody k contentTypes a) sub) api -> MatchT ((k1 :> *) (ReqBody k contentTypes a) sub) api a -> Location -> Maybe a Source #

(KnownSymbol sym, FromHttpApiData a, Matches k sub) => Matches * ((:>) k * (QueryParams * sym a) sub) Source # 

Associated Types

type MatchT ((:>) k * (QueryParams * sym a) sub) (api :: (:>) k * (QueryParams * sym a) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (QueryParams * sym a) sub) api -> MatchT ((k :> *) (QueryParams * sym a) sub) api a -> Location -> Maybe a Source #

(KnownSymbol sym, FromHttpApiData a, Matches k sub) => Matches * ((:>) k * (QueryParam * sym a) sub) Source # 

Associated Types

type MatchT ((:>) k * (QueryParam * sym a) sub) (api :: (:>) k * (QueryParam * sym a) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (QueryParam * sym a) sub) api -> MatchT ((k :> *) (QueryParam * sym a) sub) api a -> Location -> Maybe a Source #

(KnownSymbol sym, Matches k sub) => Matches * ((:>) k * (QueryFlag sym) sub) Source # 

Associated Types

type MatchT ((:>) k * (QueryFlag sym) sub) (api :: (:>) k * (QueryFlag sym) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (QueryFlag sym) sub) api -> MatchT ((k :> *) (QueryFlag sym) sub) api a -> Location -> Maybe a Source #

Matches k sub => Matches * ((:>) k * HttpVersion sub) Source # 

Associated Types

type MatchT ((:>) k * HttpVersion sub) (api :: (:>) k * HttpVersion sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) HttpVersion sub) api -> MatchT ((k :> *) HttpVersion sub) api a -> Location -> Maybe a Source #

Matches k sub => Matches * ((:>) k * (Header sym a) sub) Source # 

Associated Types

type MatchT ((:>) k * (Header sym a) sub) (api :: (:>) k * (Header sym a) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (Header sym a) sub) api -> MatchT ((k :> *) (Header sym a) sub) api a -> Location -> Maybe a Source #

(Matches k sub, FromHttpApiData a) => Matches * ((:>) k * (CaptureAll * sym a) sub) Source # 

Associated Types

type MatchT ((:>) k * (CaptureAll * sym a) sub) (api :: (:>) k * (CaptureAll * sym a) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (CaptureAll * sym a) sub) api -> MatchT ((k :> *) (CaptureAll * sym a) sub) api a -> Location -> Maybe a Source #

(Matches k sub, FromHttpApiData a) => Matches * ((:>) k * (Capture * sym a) sub) Source # 

Associated Types

type MatchT ((:>) k * (Capture * sym a) sub) (api :: (:>) k * (Capture * sym a) sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> *) (Capture * sym a) sub) api -> MatchT ((k :> *) (Capture * sym a) sub) api a -> Location -> Maybe a Source #

(KnownSymbol s, Matches k sub) => Matches * ((:>) k Symbol s sub) Source # 

Associated Types

type MatchT ((:>) k Symbol s sub) (api :: (:>) k Symbol s sub) r :: * Source #

Methods

matchLocation :: Proxy ((k :> Symbol) s sub) api -> MatchT ((k :> Symbol) s sub) api a -> Location -> Maybe a Source #

Matches * (Verb k k1 method statusCode contentTypes a) Source # 

Associated Types

type MatchT (Verb k k1 method statusCode contentTypes a) (api :: Verb k k1 method statusCode contentTypes a) r :: * Source #

Methods

matchLocation :: Proxy (Verb k k1 method statusCode contentTypes a) api -> MatchT (Verb k k1 method statusCode contentTypes a) api a -> Location -> Maybe a Source #