-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A family of combinators for defining webservices APIs -- -- A family of combinators for defining webservices APIs and serving them -- -- You can learn about the basics in the tutorial. -- -- CHANGELOG @package servant @version 0.8 module Servant.API.Experimental.Auth -- | A generalized Authentication combinator. Use this if you have a -- non-standard authentication technique. -- -- NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE. data AuthProtect (tag :: k) module Servant.API.Raw -- | Endpoint for plugging in your own Wai Applications. -- -- The given Application will get the request as received by the -- server, potentially with a modified (stripped) pathInfo if -- the Application is being routed with :>. -- -- In addition to just letting you plug in your existing WAI -- Applications, this can also be used with -- serveDirectory to serve static files stored in a particular -- directory on your filesystem data Raw -- | A collection of basic Content-Types (also known as Internet Media -- Types, or MIME types). Additionally, this module provides classes that -- encapsulate how to serialize or deserialize values to or from a -- particular Content-Type. -- -- Content-Types are used in ReqBody and the method combinators: -- --
-- >>> type MyEndpoint = ReqBody '[JSON, PlainText] Book :> Get '[JSON, PlainText] Book ---- -- Meaning the endpoint accepts requests of Content-Type -- application/json or text/plain;charset-utf8, and -- returns data in either one of those formats (depending on the -- Accept header). -- -- If you would like to support Content-Types beyond those provided here, -- then: -- --
-- >>> import Network.HTTP.Media ((//), (/:))
--
-- >>> data HTML
--
-- >>> :{
-- instance Accept HTML where
-- contentType _ = "text" // "html" /: ("charset", "utf-8")
-- :}
--
class Accept ctype
contentType :: Accept ctype => Proxy ctype -> MediaType
-- | Instantiate this class to register a way of serializing a type based
-- on the Accept header.
--
-- Example:
--
--
-- data MyContentType
--
-- instance Accept MyContentType where
-- contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8")
--
-- instance Show a => MimeRender MyContentType a where
-- mimeRender _ val = pack ("This is MINE! " ++ show val)
--
-- type MyAPI = "path" :> Get '[MyContentType] Int
--
class Accept ctype => MimeRender ctype a
mimeRender :: MimeRender ctype a => Proxy ctype -> a -> ByteString
-- | Instantiate this class to register a way of deserializing a type based
-- on the request's Content-Type header.
--
-- -- >>> import Network.HTTP.Media hiding (Accept) -- -- >>> import qualified Data.ByteString.Lazy.Char8 as BSC -- -- >>> data MyContentType = MyContentType String ---- --
-- >>> :{
-- instance Accept MyContentType where
-- contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8")
-- :}
--
--
--
-- >>> :{
-- instance Read a => MimeUnrender MyContentType a where
-- mimeUnrender _ bs = case BSC.take 12 bs of
-- "MyContentType" -> return . read . BSC.unpack $ BSC.drop 12 bs
-- _ -> Left "didn't start with the magic incantation"
-- :}
--
--
-- -- >>> type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int --class Accept ctype => MimeUnrender ctype a mimeUnrender :: MimeUnrender ctype a => Proxy ctype -> ByteString -> Either String a -- | A type for responses without content-body. data NoContent NoContent :: NoContent newtype AcceptHeader AcceptHeader :: ByteString -> AcceptHeader class (AllMime list) => AllCTRender (list :: [*]) a handleAcceptH :: AllCTRender list a => Proxy list -> AcceptHeader -> a -> Maybe (ByteString, ByteString) class AllCTUnrender (list :: [*]) a handleCTypeH :: AllCTUnrender list a => Proxy list -> ByteString -> ByteString -> Maybe (Either String a) class AllMime (list :: [*]) allMime :: AllMime list => Proxy list -> [MediaType] class (AllMime list) => AllMimeRender (list :: [*]) a allMimeRender :: AllMimeRender list a => Proxy list -> a -> [(MediaType, ByteString)] class (AllMime list) => AllMimeUnrender (list :: [*]) a allMimeUnrender :: AllMimeUnrender list a => Proxy list -> ByteString -> [(MediaType, Either String a)] -- | A type that can be converted from -- application/x-www-form-urlencoded, with the possibility of -- failure. class FromFormUrlEncoded a fromFormUrlEncoded :: FromFormUrlEncoded a => [(Text, Text)] -> Either String a -- | A type that can be converted to -- application/x-www-form-urlencoded class ToFormUrlEncoded a toFormUrlEncoded :: ToFormUrlEncoded a => a -> [(Text, Text)] -- | Like eitherDecode but allows all JSON values instead of just -- objects and arrays. -- -- Will handle trailing whitespace, but not trailing junk. ie. -- --
-- >>> eitherDecodeLenient "1 " :: Either String Int -- Right 1 ---- --
-- >>> eitherDecodeLenient "1 junk" :: Either String Int -- Left "trailing junk after valid JSON: endOfInput" --eitherDecodeLenient :: FromJSON a => ByteString -> Either String a canHandleAcceptH :: AllMime list => Proxy list -> AcceptHeader -> Bool instance GHC.Generics.Generic Servant.API.ContentTypes.NoContent instance GHC.Read.Read Servant.API.ContentTypes.NoContent instance GHC.Classes.Eq Servant.API.ContentTypes.NoContent instance GHC.Show.Show Servant.API.ContentTypes.NoContent instance GHC.Generics.Generic Servant.API.ContentTypes.AcceptHeader instance GHC.Read.Read Servant.API.ContentTypes.AcceptHeader instance GHC.Show.Show Servant.API.ContentTypes.AcceptHeader instance GHC.Classes.Eq Servant.API.ContentTypes.AcceptHeader instance Servant.API.ContentTypes.Accept Servant.API.ContentTypes.JSON instance Servant.API.ContentTypes.Accept Servant.API.ContentTypes.FormUrlEncoded instance Servant.API.ContentTypes.Accept Servant.API.ContentTypes.PlainText instance Servant.API.ContentTypes.Accept Servant.API.ContentTypes.OctetStream instance (Servant.API.ContentTypes.Accept ct, Servant.API.ContentTypes.AllMime cts, Servant.API.ContentTypes.AllMimeRender (ct : cts) a) => Servant.API.ContentTypes.AllCTRender (ct : cts) a instance Servant.API.ContentTypes.AllMimeUnrender ctyps a => Servant.API.ContentTypes.AllCTUnrender ctyps a instance Servant.API.ContentTypes.AllMime '[] instance (Servant.API.ContentTypes.Accept ctyp, Servant.API.ContentTypes.AllMime ctyps) => Servant.API.ContentTypes.AllMime (ctyp : ctyps) instance Servant.API.ContentTypes.MimeRender ctyp a => Servant.API.ContentTypes.AllMimeRender '[ctyp] a instance (Servant.API.ContentTypes.MimeRender ctyp a, Servant.API.ContentTypes.AllMimeRender (ctyp' : ctyps) a) => Servant.API.ContentTypes.AllMimeRender (ctyp : ctyp' : ctyps) a instance Servant.API.ContentTypes.Accept ctyp => Servant.API.ContentTypes.AllMimeRender '[ctyp] Servant.API.ContentTypes.NoContent instance Servant.API.ContentTypes.AllMime (ctyp : ctyp' : ctyps) => Servant.API.ContentTypes.AllMimeRender (ctyp : ctyp' : ctyps) Servant.API.ContentTypes.NoContent instance Servant.API.ContentTypes.AllMimeUnrender '[] a instance (Servant.API.ContentTypes.MimeUnrender ctyp a, Servant.API.ContentTypes.AllMimeUnrender ctyps a) => Servant.API.ContentTypes.AllMimeUnrender (ctyp : ctyps) a instance Data.Aeson.Types.Class.ToJSON a => Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.JSON a instance Servant.API.ContentTypes.ToFormUrlEncoded a => Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.FormUrlEncoded a instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Data.Text.Internal.Lazy.Text instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText Data.Text.Internal.Text instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.PlainText GHC.Base.String instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.OctetStream Data.ByteString.Lazy.Internal.ByteString instance Servant.API.ContentTypes.MimeRender Servant.API.ContentTypes.OctetStream Data.ByteString.Internal.ByteString instance Data.Aeson.Types.Class.FromJSON a => Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.JSON a instance Servant.API.ContentTypes.FromFormUrlEncoded a => Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.FormUrlEncoded a instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.PlainText Data.Text.Internal.Lazy.Text instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.PlainText Data.Text.Internal.Text instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.PlainText GHC.Base.String instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.OctetStream Data.ByteString.Lazy.Internal.ByteString instance Servant.API.ContentTypes.MimeUnrender Servant.API.ContentTypes.OctetStream Data.ByteString.Internal.ByteString instance Servant.API.ContentTypes.ToFormUrlEncoded [(Data.Text.Internal.Text, Data.Text.Internal.Text)] instance Servant.API.ContentTypes.FromFormUrlEncoded [(Data.Text.Internal.Text, Data.Text.Internal.Text)] module Servant.API.BasicAuth -- | Combinator for Basic Access Authentication. -- --
-- >>> type Post204 contentTypes a = Verb 'POST 204 contentTypes a --data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) a -- | GET with 200 status code. type Get = Verb GET 200 -- | POST with 200 status code. type Post = Verb POST 200 -- | PUT with 200 status code. type Put = Verb PUT 200 -- | DELETE with 200 status code. type Delete = Verb DELETE 200 -- | PATCH with 200 status code. type Patch = Verb PATCH 200 -- | POST with 201 status code. type PostCreated = Verb POST 201 -- | GET with 202 status code. type GetAccepted = Verb GET 202 -- | POST with 202 status code. type PostAccepted = Verb POST 202 -- | DELETE with 202 status code. type DeleteAccepted = Verb DELETE 202 -- | PATCH with 202 status code. type PatchAccepted = Verb PATCH 202 -- | PUT with 202 status code. type PutAccepted = Verb PUT 202 -- | GET with 203 status code. type GetNonAuthoritative = Verb GET 203 -- | POST with 203 status code. type PostNonAuthoritative = Verb POST 203 -- | DELETE with 203 status code. type DeleteNonAuthoritative = Verb DELETE 203 -- | PATCH with 203 status code. type PatchNonAuthoritative = Verb PATCH 203 -- | PUT with 203 status code. type PutNonAuthoritative = Verb PUT 203 -- | GET with 204 status code. type GetNoContent = Verb GET 204 -- | POST with 204 status code. type PostNoContent = Verb POST 204 -- | DELETE with 204 status code. type DeleteNoContent = Verb DELETE 204 -- | PATCH with 204 status code. type PatchNoContent = Verb PATCH 204 -- | PUT with 204 status code. type PutNoContent = Verb PUT 204 -- | GET with 205 status code. type GetResetContent = Verb GET 205 -- | POST with 205 status code. type PostResetContent = Verb POST 205 -- | DELETE with 205 status code. type DeleteResetContent = Verb DELETE 205 -- | PATCH with 205 status code. type PatchResetContent = Verb PATCH 205 -- | PUT with 205 status code. type PutResetContent = Verb PUT 205 -- | GET with 206 status code. type GetPartialContent = Verb GET 206 class ReflectMethod a reflectMethod :: ReflectMethod a => Proxy a -> Method -- | HTTP standard method (as defined by RFC 2616, and PATCH which is -- defined by RFC 5789). data StdMethod :: * GET :: StdMethod POST :: StdMethod HEAD :: StdMethod PUT :: StdMethod DELETE :: StdMethod TRACE :: StdMethod CONNECT :: StdMethod OPTIONS :: StdMethod PATCH :: StdMethod instance forall k1 (method :: k1) (statusCode :: GHC.Types.Nat) (contentTypes :: [GHC.Types.*]) k (a :: k). GHC.Generics.Generic (Servant.API.Verbs.Verb method statusCode contentTypes a) instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.GET instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.POST instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.PUT instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.DELETE instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.PATCH instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.HEAD instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.OPTIONS instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.TRACE instance Servant.API.Verbs.ReflectMethod 'Network.HTTP.Types.Method.CONNECT module Servant.API.WithNamedContext -- | WithNamedContext names a specific tagged context to use for the -- combinators in the API. (See also in servant-server, -- Servant.Server.Context.) For example: -- --
-- type UseNamedContextAPI = WithNamedContext "myContext" '[String] ( -- ReqBody '[JSON] Int :> Get '[JSON] Int) ---- -- Both the ReqBody and Get combinators will use the -- WithNamedContext with type tag "myContext" as their context. -- -- Contexts are only relevant for servant-server. -- -- For more information, see the tutorial. data WithNamedContext (name :: Symbol) (subContext :: [*]) subApi module Servant.API.Vault -- | A persistent store for values of arbitrary types. -- -- This variant is the simplest and creates keys in the IO monad. -- See the module Data.Vault.ST if you want to use it with the -- ST monad instead. type Vault = Vault RealWorld module Servant.API.IsSecure -- | Was this request made over an SSL connection? -- -- Note that this value will not tell you if the client originally made -- this request over SSL, but rather whether the current connection is -- SSL. The distinction lies with reverse proxies. In many cases, the -- client will connect to a load balancer over SSL, but connect to the -- WAI handler without SSL. In such a case, the handlers would get -- NotSecure, but from a user perspective, there is a secure -- connection. data IsSecure -- | the connection to the server is secure (HTTPS) Secure :: IsSecure -- | the connection to the server is not secure (HTTP) NotSecure :: IsSecure module Servant.API.RemoteHost -- | Provides access to the host or IP address from which the HTTP request -- was sent. data RemoteHost module Servant.API.ReqBody -- | Extract the request body as a value of type a. -- -- Example: -- --
-- >>> -- POST /books -- -- >>> type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book --data ReqBody (contentTypes :: [*]) a module Servant.API.QueryParam -- | Lookup a potentially value-less query string parameter with boolean -- semantics. If the param sym is there without any value, or if -- it's there with value "true" or "1", it's interpreted as True. -- Otherwise, it's interpreted as False. -- -- Example: -- --
-- >>> -- /books?published -- -- >>> type MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book] --data QueryFlag (sym :: Symbol) -- | Lookup the value associated to the sym query string parameter -- and try to extract it as a value of type a. -- -- Example: -- --
-- >>> -- /books?author=<author name> -- -- >>> type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book] --data QueryParam (sym :: Symbol) a -- | Lookup the values associated to the sym query string -- parameter and try to extract it as a value of type [a]. This -- is typically meant to support query string parameters of the form -- param[]=val1¶m[]=val2 and so on. Note that servant -- doesn't actually require the []s and will fetch the values -- just fine with param=val1¶m=val2, too. -- -- Example: -- --
-- >>> -- /books?authors[]=<author1>&authors[]=<author2>&... -- -- >>> type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book] --data QueryParams (sym :: Symbol) a module Servant.API.HttpVersion -- | HTTP Version. -- -- Note that the Show instance is intended merely for debugging. data HttpVersion :: * HttpVersion :: ~Int -> ~Int -> HttpVersion [httpMajor] :: HttpVersion -> ~Int [httpMinor] :: HttpVersion -> ~Int module Servant.API.Header -- | Extract the given header's value as a value of type a. -- -- Example: -- --
-- >>> newtype Referer = Referer Text deriving (Eq, Show) -- -- >>> -- -- >>> -- GET /view-my-referer -- -- >>> type MyApi = "view-my-referer" :> Header "from" Referer :> Get '[JSON] Referer --data Header (sym :: Symbol) a Header :: a -> Header a MissingHeader :: Header a UndecodableHeader :: ByteString -> Header a instance GHC.Base.Functor (Servant.API.Header.Header sym) instance GHC.Show.Show a => GHC.Show.Show (Servant.API.Header.Header sym a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Servant.API.Header.Header sym a) -- | This module provides facilities for adding headers to a response. -- --
-- >>> let headerVal = addHeader "some-url" 5 :: Headers '[Header "Location" String] Int ---- -- The value is added to the header specified by the type -- (Location in the example above). module Servant.API.ResponseHeaders -- | Response Header objects. You should never need to construct one -- directly. Instead, use addHeader. data Headers ls a Headers :: a -> HList ls -> Headers ls a -- | The underlying value of a Headers [getResponse] :: Headers ls a -> a -- | HList of headers. [getHeadersHList] :: Headers ls a -> HList ls class AddHeader h v orig new | h v orig -> new, new -> h, new -> v, new -> orig addHeader :: AddHeader h v orig new => v -> orig -> new class BuildHeadersTo hs -- | Note: if there are multiple occurences of a header in the argument, -- the values are interspersed with commas before deserialization (see -- RFC2616 Sec 4.2) buildHeadersTo :: BuildHeadersTo hs => [Header] -> HList hs class GetHeaders ls getHeaders :: GetHeaders ls => ls -> [Header] data HList a [HNil] :: HList '[] [HCons] :: Header h x -> HList xs -> HList (Header h x : xs) instance GHC.Base.Functor (Servant.API.ResponseHeaders.Headers ls) instance Servant.API.ResponseHeaders.BuildHeadersTo '[] instance (Data.ByteString.Conversion.From.FromByteString v, Servant.API.ResponseHeaders.BuildHeadersTo xs, GHC.TypeLits.KnownSymbol h) => Servant.API.ResponseHeaders.BuildHeadersTo (Servant.API.Header.Header h v : xs) instance Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.HList '[]) instance (GHC.TypeLits.KnownSymbol h, Data.ByteString.Conversion.To.ToByteString x, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.HList xs)) => Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.HList (Servant.API.Header.Header h x : xs)) instance Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers '[] a) instance (GHC.TypeLits.KnownSymbol h, Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.HList rest), Data.ByteString.Conversion.To.ToByteString v) => Servant.API.ResponseHeaders.GetHeaders (Servant.API.ResponseHeaders.Headers (Servant.API.Header.Header h v : rest) a) instance (GHC.TypeLits.KnownSymbol h, Data.ByteString.Conversion.To.ToByteString v) => Servant.API.ResponseHeaders.AddHeader h v (Servant.API.ResponseHeaders.Headers (fst : rest) a) (Servant.API.ResponseHeaders.Headers (Servant.API.Header.Header h v : fst : rest) a) instance (GHC.TypeLits.KnownSymbol h, Data.ByteString.Conversion.To.ToByteString v, new ~ Servant.API.ResponseHeaders.Headers '[Servant.API.Header.Header h v] a) => Servant.API.ResponseHeaders.AddHeader h v a new module Servant.API.Capture -- | Capture a value from the request path under a certain type a. -- -- Example: -- --
-- >>> -- GET /books/:isbn -- -- >>> type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book --data Capture (sym :: Symbol) a module Servant.API.Alternative -- | Union of two APIs, first takes precedence in case of overlap. -- -- Example: -- --
-- >>> :{
-- type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
-- :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] () -- POST /books
-- :}
--
data (:<|>) a b
(:<|>) :: a -> b -> (:<|>) a b
instance (GHC.Enum.Bounded a, GHC.Enum.Bounded b) => GHC.Enum.Bounded (a Servant.API.Alternative.:<|> b)
instance Data.Foldable.Foldable ((Servant.API.Alternative.:<|>) a)
instance Data.Traversable.Traversable ((Servant.API.Alternative.:<|>) a)
instance GHC.Base.Functor ((Servant.API.Alternative.:<|>) a)
instance (GHC.Show.Show a, GHC.Show.Show b) => GHC.Show.Show (a Servant.API.Alternative.:<|> b)
instance (GHC.Classes.Eq a, GHC.Classes.Eq b) => GHC.Classes.Eq (a Servant.API.Alternative.:<|> b)
instance (GHC.Base.Monoid a, GHC.Base.Monoid b) => GHC.Base.Monoid (a Servant.API.Alternative.:<|> b)
module Servant.API.Sub
-- | The contained API (second argument) can be found under ("/" ++
-- path) (path being the first argument).
--
-- Example:
--
-- -- >>> -- GET /hello/world -- -- >>> -- returning a JSON encoded World value -- -- >>> type MyApi = "hello" :> "world" :> Get '[JSON] World --data (:>) (path :: k) a -- | Type safe generation of internal links. -- -- Given an API with a few endpoints: -- --
-- >>> :set -XDataKinds -XTypeFamilies -XTypeOperators -- -- >>> import Servant.API -- -- >>> import Servant.Utils.Links -- -- >>> import Data.Proxy -- -- >>> -- -- >>> -- -- >>> -- -- >>> type Hello = "hello" :> Get '[JSON] Int -- -- >>> type Bye = "bye" :> QueryParam "name" String :> Delete '[JSON] NoContent -- -- >>> type API = Hello :<|> Bye -- -- >>> let api = Proxy :: Proxy API ---- -- It is possible to generate links that are guaranteed to be within -- API with safeLink. The first argument to -- safeLink is a type representing the API you would like to -- restrict links to. The second argument is the destination endpoint you -- would like the link to point to, this will need to end with a verb -- like GET or POST. Further arguments may be required depending on the -- type of the endpoint. If everything lines up you will get a URI -- out the other end. -- -- You may omit QueryParams and the like should you not want to -- provide them, but types which form part of the URL path like -- Capture must be included. The reason you may want to omit -- QueryParams is that safeLink is a bit magical: if parameters -- are included that could take input it will return a function that -- accepts that input and generates a link. This is best shown with an -- example. Here, a link is generated with no parameters: -- --
-- >>> let hello = Proxy :: Proxy ("hello" :> Get '[JSON] Int)
--
-- >>> print (safeLink api hello :: URI)
-- hello
--
--
-- If the API has an endpoint with parameters then we can generate links
-- with or without those:
--
--
-- >>> let with = Proxy :: Proxy ("bye" :> QueryParam "name" String :> Delete '[JSON] NoContent)
--
-- >>> print $ safeLink api with (Just "Hubert")
-- bye?name=Hubert
--
--
--
-- >>> let without = Proxy :: Proxy ("bye" :> Delete '[JSON] NoContent)
--
-- >>> print $ safeLink api without
-- bye
--
--
-- If you would like create a helper for generating links only within
-- that API, you can partially apply safeLink if you specify a correct
-- type signature like so:
--
--
-- >>> :set -XConstraintKinds
--
-- >>> :{
--
-- >>> let apiLink :: (IsElem endpoint API, HasLink endpoint)
--
-- >>> => Proxy endpoint -> MkLink endpoint
--
-- >>> apiLink = safeLink api
--
-- >>> :}
--
--
-- Attempting to construct a link to an endpoint that does not exist in
-- api will result in a type error like this:
--
--
-- >>> let bad_link = Proxy :: Proxy ("hello" :> Delete '[JSON] NoContent)
--
-- >>> safeLink api bad_link
-- ...
-- ...Could not deduce...
-- ...
--
--
-- This error is essentially saying that the type family couldn't find
-- bad_link under api after trying the open (but empty) type family
-- IsElem' as a last resort.
module Servant.Utils.Links
-- | Create a valid (by construction) relative URI with query params.
--
-- This function will only typecheck if endpoint is part of the
-- API api
safeLink :: forall endpoint api. (IsElem endpoint api, HasLink endpoint) => Proxy api -> Proxy endpoint -> MkLink endpoint
-- | Represents a general universal resource identifier using its component
-- parts.
--
-- For example, for the URI
--
-- -- foo://anonymous@www.haskell.org:42/ghc?query#frag ---- -- the components are: data URI :: * URI :: String -> Maybe URIAuth -> String -> String -> String -> URI -- |
-- foo: --[uriScheme] :: URI -> String -- |
-- //anonymous@www.haskell.org:42 --[uriAuthority] :: URI -> Maybe URIAuth -- |
-- /ghc --[uriPath] :: URI -> String -- |
-- ?query --[uriQuery] :: URI -> String -- |
-- #frag --[uriFragment] :: URI -> String -- | Construct a toLink for an endpoint. class HasLink endpoint where type MkLink endpoint where { type family MkLink endpoint; } toLink :: HasLink endpoint => Proxy endpoint -> Link -> MkLink endpoint linkURI :: Link -> URI -- | A safe link datatype. The only way of constructing a Link is -- using safeLink, which means any Link is guaranteed to be -- part of the mentioned API. data Link -- | You may use this type family to tell the type checker that your custom -- type may be skipped as part of a link. This is useful for things like -- QueryParam that are optional in a URI and do not affect them if -- they are omitted. -- --
-- >>> data CustomThing -- -- >>> type instance IsElem' e (CustomThing :> s) = IsElem e s ---- -- Note that IsElem is called, which will mutually recurse back to -- IsElem' if it exhausts all other options again. -- -- Once you have written a HasLink instance for CustomThing you are ready -- to go. -- | Closed type family, check if endpoint is within api -- | If either a or b produce an empty constraint, produce an empty -- constraint. instance GHC.Show.Show Servant.Utils.Links.Link instance forall k (a :: k). GHC.Show.Show (Servant.Utils.Links.Param a) instance Web.HttpApiData.Internal.ToHttpApiData Servant.Utils.Links.Link instance forall k (sym :: GHC.Types.Symbol) (sub :: k). (GHC.TypeLits.KnownSymbol sym, Servant.Utils.Links.HasLink sub) => Servant.Utils.Links.HasLink (sym Servant.API.Sub.:> sub) instance forall k (sym :: GHC.Types.Symbol) v (sub :: k). (GHC.TypeLits.KnownSymbol sym, Web.HttpApiData.Internal.ToHttpApiData v, Servant.Utils.Links.HasLink sub) => Servant.Utils.Links.HasLink (Servant.API.QueryParam.QueryParam sym v Servant.API.Sub.:> sub) instance forall k (sym :: GHC.Types.Symbol) v (sub :: k). (GHC.TypeLits.KnownSymbol sym, Web.HttpApiData.Internal.ToHttpApiData v, Servant.Utils.Links.HasLink sub) => Servant.Utils.Links.HasLink (Servant.API.QueryParam.QueryParams sym v Servant.API.Sub.:> sub) instance forall k (sym :: GHC.Types.Symbol) (sub :: k). (GHC.TypeLits.KnownSymbol sym, Servant.Utils.Links.HasLink sub) => Servant.Utils.Links.HasLink (Servant.API.QueryParam.QueryFlag sym Servant.API.Sub.:> sub) instance forall k k1 (sub :: k) (ct :: [GHC.Types.*]) (a :: k1). Servant.Utils.Links.HasLink sub => Servant.Utils.Links.HasLink (Servant.API.ReqBody.ReqBody ct a Servant.API.Sub.:> sub) instance forall k v (sub :: k) (sym :: GHC.Types.Symbol). (Web.HttpApiData.Internal.ToHttpApiData v, Servant.Utils.Links.HasLink sub) => Servant.Utils.Links.HasLink (Servant.API.Capture.Capture sym v Servant.API.Sub.:> sub) instance forall k (sub :: k) (sym :: GHC.Types.Symbol) a. Servant.Utils.Links.HasLink sub => Servant.Utils.Links.HasLink (Servant.API.Header.Header sym a Servant.API.Sub.:> sub) instance forall k (sub :: k). Servant.Utils.Links.HasLink sub => Servant.Utils.Links.HasLink (Servant.API.RemoteHost.RemoteHost Servant.API.Sub.:> sub) instance forall k (sub :: k) (realm :: GHC.Types.Symbol) a. Servant.Utils.Links.HasLink sub => Servant.Utils.Links.HasLink (Servant.API.BasicAuth.BasicAuth realm a Servant.API.Sub.:> sub) instance forall k1 k (m :: k1) (s :: GHC.Types.Nat) (ct :: [GHC.Types.*]) (a :: k). Servant.Utils.Links.HasLink (Servant.API.Verbs.Verb m s ct a) instance Servant.Utils.Links.HasLink Servant.API.Raw.Raw module Servant.API -- | This is a module containing an API with all API combinators. It -- is used for testing only (in particular, checking that instances exist -- for the core servant classes for each combinator), and should not be -- imported. module Servant.API.Internal.Test.ComprehensiveAPI type GET = Get '[JSON] NoContent type ComprehensiveAPI = GET :<|> (Get '[JSON] Int :<|> ((Capture "foo" Int :> GET) :<|> ((Header "foo" Int :> GET) :<|> ((HttpVersion :> GET) :<|> ((IsSecure :> GET) :<|> ((QueryParam "foo" Int :> GET) :<|> ((QueryParams "foo" Int :> GET) :<|> ((QueryFlag "foo" :> GET) :<|> ((RemoteHost :> GET) :<|> ((ReqBody '[JSON] Int :> GET) :<|> (Get '[JSON] (Headers '[Header "foo" Int] NoContent) :<|> (("foo" :> GET) :<|> ((Vault :> GET) :<|> (Verb POST 204 '[JSON] NoContent :<|> (Verb POST 204 '[JSON] Int :<|> WithNamedContext "foo" '[] GET))))))))))))))) comprehensiveAPI :: Proxy ComprehensiveAPI module Servant.Utils.Enter class Enter typ arg ret | typ arg -> ret, typ ret -> arg enter :: Enter typ arg ret => arg -> typ -> ret -- | A natural transformation from m to n. Used to -- enter particular datatypes. newtype (:~>) m n Nat :: (forall a. m a -> n a) -> (:~>) m n [unNat] :: (:~>) m n -> forall a. m a -> n a -- | Like lift. liftNat :: (MonadTrans t, Monad m) => m :~> t m runReaderTNat :: r -> (ReaderT r m :~> m) evalStateTLNat :: Monad m => s -> (StateT s m :~> m) evalStateTSNat :: Monad m => s -> (StateT s m :~> m) -- | Log the contents of WriterT with the function provided as the -- first argument, and return the value of the WriterT -- computation logWriterTSNat :: MonadIO m => (w -> IO ()) -> (WriterT w m :~> m) -- | Like logWriterTSNat, but for strict WriterT. logWriterTLNat :: MonadIO m => (w -> IO ()) -> (WriterT w m :~> m) -- | Like mmorph's hoist. hoistNat :: (MFunctor t, Monad m) => (m :~> n) -> (t m :~> t n) -- | Like mmorph's embed. embedNat :: (MMonad t, Monad n) => (m :~> t n) -> (t m :~> t n) -- | Like mmorph's squash. squashNat :: (Monad m, MMonad t) => t (t m) :~> t m -- | Like mmorph's generalize. generalizeNat :: Applicative m => Identity :~> m instance (Servant.Utils.Enter.Enter typ1 arg1 ret1, Servant.Utils.Enter.Enter typ2 arg2 ret2, arg1 ~ arg2) => Servant.Utils.Enter.Enter (typ1 Servant.API.Alternative.:<|> typ2) arg1 (ret1 Servant.API.Alternative.:<|> ret2) instance Servant.Utils.Enter.Enter b arg ret => Servant.Utils.Enter.Enter (a -> b) arg (a -> ret) instance Control.Category.Category (Servant.Utils.Enter.:~>) instance Servant.Utils.Enter.Enter (m a) (m Servant.Utils.Enter.:~> n) (n a)