servant-0.2: A family of combinators for defining webservices APIs and serving them

Safe HaskellNone
LanguageHaskell2010

Servant.Utils.Links

Description

Type safe internal links.

Provides the function mkLink:

  type API = Proxy ("hello" :> Get Int
               :| "bye" :> QueryParam "name" String :> Post Bool)

  api :: API
  api = proxy

  link1 :: Proxy ("hello" :> Get Int)
  link1 = proxy

  link2 :: Proxy ("hello" :> Delete)
  link2 = proxy

  mkLink link1 API  --  typechecks, returns 'Link "/hello"'

  mkLink link2  API  -- doesn't typecheck

That is, mkLink takes two arguments, a link proxy and a sitemap, and returns a Link, but only typechecks if the link proxy is a valid link, and part of the sitemap.

N.B.: mkLink assumes a capture matches any string (without slashes).

Synopsis

Documentation

type family Or a b Source

Equations

Or False False = False 
Or True b = True 
Or a True = True 

type family And a b Source

Equations

And True True = True 
And a False = False 
And False b = False 

type family IsElem a s Source

Equations

IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb) 
IsElem (e :> sa) (e :> sb) = IsElem sa sb 
IsElem (e :> sa) (Capture x y :> sb) = IsElem sa sb 
IsElem sa (ReqBody x :> sb) = IsElem sa sb 
IsElem sa (QueryParam x y :> sb) = IsElem sa sb 
IsElem e e = True 
IsElem e a = False 

type family IsLink'' l Source

Equations

IsLink'' (e :> Get x) = IsLink' e 
IsLink'' (e :> Post x) = IsLink' e 
IsLink'' (e :> Put x) = IsLink' e 
IsLink'' (e :> Delete) = IsLink' e 
IsLink'' a = False 

type family IsLink' e Source

Equations

IsLink' (f :: Symbol) = True 

type family IsLink e Source

Equations

IsLink (a :> b) = Or (And (IsLink' a) (IsLink'' b)) (IsLink'' (a :> b)) 

class ValidLinkIn f s where Source

The 'ValidLinkIn f s' constraint holds when s is an API that contains f, and f is a link.

Methods

mkLink Source

Arguments

:: f 
-> s 
-> Link

This function will only typecheck if f is an URI within s

Instances

((~) Bool (IsElem f s) True, (~) Bool (IsLink f) True, VLinkHelper * f) => ValidLinkIn f s 

data Link Source

Constructors

Link String 

class VLinkHelper f where Source

Methods

vlh :: forall proxy. proxy f -> String Source

Instances