HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleservant-server-0.20.2Haskell2010

Servant

  • 98 types
  • 21 classes
  • 23 values

This module and its submodules can be used to define servant APIs. Note that these API definitions don't directly implement a server (or anything else).

datadata UVerb (method :: StdMethod) (contentTypes :: [Type]) (as :: [Type])
#

A variant of Verb that can have any of a number of response values and status codes.

FUTUREWORK: it would be nice to make Verb a special case of UVerb, and only write instances for HasServer etc. for the latter, getting them for the former for free. Something like:

type Verb method statusCode contentTypes a = UVerb method contentTypes [WithStatus statusCode a]

Backwards compatibility is tricky, though: this type alias would mean people would have to use respond instead of pure or return, so all old handlers would have to be rewritten.

Instances5HasLink, HasServer, AtMostOneFragment, MkLink, ServerT
  • HasLink (UVerb m ct a)Defined in servant-0.20.2 · Servant.Links
  • (ReflectMethod method, AllMime contentTypes, All (IsServerResourceWithStatus contentTypes) as, Unique (Statuses as)) => HasServer (UVerb method contentTypes as) contextDefined in servant-server-0.20.2 · Servant.Server.UVerb · orphan
  • AtMostOneFragment (UVerb m cts as)Defined in servant-0.20.2 · Servant.API.TypeLevel
  • type MkLink (UVerb m ct a) r = rDefined in servant-0.20.2 · Servant.Links
  • type ServerT (UVerb method contentTypes as) m = m (Union as)Defined in servant-server-0.20.2 · Servant.Server.UVerb · orphan
datadata (:>) (path :: k) a
#

The contained API (second argument) can be found under ("/" ++ path) (path being the first argument).

Example:

Example3 expressions
-- GET /hello/world-- returning a JSON encoded World valuetype MyApi = "hello" :> "world" :> Get '[JSON] World
Instances88HasLink, HasServer, MkLink, ServerT, …
datadata BasicAuth (realm :: Symbol) userData
#

Combinator for Basic Access Authentication.

  • IMPORTANT*: Only use Basic Auth over HTTPS! Credentials are not hashed or encrypted. Note also that because the same credentials are sent on every request, Basic Auth is not as secure as some alternatives. Further, the implementation in servant-server does not protect against some types of timing attacks.

In Basic Auth, username and password are base64-encoded and transmitted via the Authorization header. Handshakes are not required, making it relatively efficient.

Instances4HasLink, HasServer, MkLink, ServerT
typetype Header = Header' '[Optional, Strict]
#

Extract the given header's value as a value of type a. I.e. header sent by client, parsed by server.

Example:

Example4 expressions
newtype Referer = Referer Text deriving (Eq, Show)           -- GET /view-my-referertype MyApi = "view-my-referer" :> Header "from" Referer :> Get '[JSON] Referer
datadata ResponseHeader (sym :: Symbol) a
#
Instances4Functor, Eq, Show, NFData
datadata (:<|>) a b
#

Union of two APIs, first takes precedence in case of overlap.

Example:

Example1 expression
:{type MyApi = "books" :> Get '[JSON] [Book] -- GET /books       :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] () -- POST /books:}

Constructors

Instances16Bifoldable, Bifunctor, Bitraversable, Biapplicative, HasLink, HasServer, …
  • Bifoldable (:<|>)Defined in servant-0.20.2 · Servant.API.Alternative
  • Bifunctor (:<|>)Defined in servant-0.20.2 · Servant.API.Alternative
  • Bitraversable (:<|>)Defined in servant-0.20.2 · Servant.API.Alternative
  • Biapplicative (:<|>)Defined in servant-0.20.2 · Servant.API.Alternative
  • (HasLink a, HasLink b) => HasLink (a :<|> b)Defined in servant-0.20.2 · Servant.Links
  • (HasServer a context, HasServer b context) => HasServer (a :<|> b) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    A server for a :<|> b first tries to match the request against the route represented by a and if it fails tries b. You must provide a request handler for each route.

    type MyApi = "books" :> Get '[JSON] [Book] -- GET /books
            :<|> "books" :> ReqBody Book :> Post '[JSON] Book -- POST /books
    
    server :: Server MyApi
    server = listAllBooks :<|> postBook
      where listAllBooks = ...
            postBook book = ...
  • Functor ((:<|>) a)Defined in servant-0.20.2 · Servant.API.Alternative
  • Foldable ((:<|>) a)Defined in servant-0.20.2 · Servant.API.Alternative
  • Traversable ((:<|>) a)Defined in servant-0.20.2 · Servant.API.Alternative
  • (Bounded a, Bounded b) => Bounded (a :<|> b)Defined in servant-0.20.2 · Servant.API.Alternative
  • (Eq a, Eq b) => Eq (a :<|> b)Defined in servant-0.20.2 · Servant.API.Alternative
  • (Show a, Show b) => Show (a :<|> b)Defined in servant-0.20.2 · Servant.API.Alternative
  • (Semigroup a, Semigroup b) => Semigroup (a :<|> b)Defined in servant-0.20.2 · Servant.API.Alternative
  • (Monoid a, Monoid b) => Monoid (a :<|> b)Defined in servant-0.20.2 · Servant.API.Alternative
  • type MkLink (a :<|> b) r = MkLink a r :<|> MkLink b rDefined in servant-0.20.2 · Servant.Links
  • type ServerT (a :<|> b) m = ServerT a m :<|> ServerT b mDefined in servant-server-0.20.2 · Servant.Server.Internal
classclass Accept (ctype :: k) where
#

Instances of Accept represent mimetypes. They are used for matching against the Accept HTTP header of the request, and for setting the Content-Type header of the response

Example:

Example3 expressions
import Network.HTTP.Media ((//), (/:))data HTML:{instance Accept HTML where   contentType _ = "text" // "html" /: ("charset", "utf-8"):}
Instances4Accept
  • Accept FormUrlEncodedDefined in servant-0.20.2 · Servant.API.ContentTypes
    application/x-www-form-urlencoded
  • Accept JSONDefined in servant-0.20.2 · Servant.API.ContentTypes
    application/json
  • Accept OctetStreamDefined in servant-0.20.2 · Servant.API.ContentTypes
    application/octet-stream
  • Accept PlainTextDefined in servant-0.20.2 · Servant.API.ContentTypes
    text/plain;charset=utf-8
datadata Capture' (mods :: [Type]) (sym :: Symbol) a
#

Capture which can be modified. For example with Description.

Instances4HasLink, HasServer, MkLink, ServerT
datadata CaptureAll (sym :: Symbol) a
#

Capture all remaining values from the request path under a certain type a.

Example:

Example2 expressions
-- GET /src/*type MyAPI = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
Instances4HasLink, HasServer, MkLink, ServerT
  • (ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub)Defined in servant-0.20.2 · Servant.Links
  • (KnownSymbol capture, FromHttpApiData a, Typeable a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (CaptureAll capture a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use CaptureAll in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of a list of the type specified by the CaptureAll. This lets servant worry about getting values from the URL and turning them into values of the type you specify.

    You can control how they'll be converted from Text to your type by simply providing an instance of FromHttpApiData for your type.

    Example:

    type MyApi = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
    
    server :: Server MyApi
    server = getSourceFile
      where getSourceFile :: [Text] -> Handler Book
            getSourceFile pathSegments = ...
  • type MkLink (CaptureAll sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.2 · Servant.Links
  • type ServerT (CaptureAll capture a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata DeepQuery (sym :: Symbol) a
#

Extract an deep object from a query string.

Example:

Example2 expressions
-- /books?filter[author][name]=<author name>&filter[year]=<book year>type MyApi = "books" :> DeepQuery "filter" BookQuery :> Get '[JSON] [Book]
Instances2HasServer, ServerT
  • (KnownSymbol sym, FromDeepQuery a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (DeepQuery sym a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use DeepQuery "symbol" a in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of type a.

    This lets you extract an object from multiple parameters in the query string, with its fields enclosed in brackets: `/books?filter[author][name]=value`. When all the fields are known in advance, it can be done with QueryParam (it can still be tedious if you the object has many fields). When some fields are dynamic, it cannot be done with @QueryParam.

    The way the object is constructed from the extracted fields can be controlled by providing an instance on FromDeepQuery

    Example:

    type MyApi = "books" :> DeepQuery "filter" BookQuery :> Get '[JSON] [Book]
    
    server :: Server MyApi
    server = getBooksBy
      where getBooksBy :: BookQuery -> Handler [Book]
            getBooksBy query = ...filter books based on the dynamic filters provided...
  • type ServerT (DeepQuery sym a :> api) m = a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata Description (sym :: Symbol)
#

Add more verbose description for (part of) API.

Example:

Example1 expression
:{type MyApi = Description "This comment is visible in multiple Servant interpretations \ \and can be really long if necessary. \ \Haskell multiline String support is not perfect \ \but it's still very readable.":> Get '[JSON] Book:}
Instances4HasLink, HasServer, MkLink, ServerT
datadata EmptyAPI
#

An empty API: one which serves nothing. Morally speaking, this should be the unit of :<|>. Implementors of interpretations of API types should treat EmptyAPI as close to the unit as possible.

Instances10Bounded, Enum, Eq, Show, HasLink, HasServer, …
datadata Fragment a
#

Document the URI fragment in API. Useful in combination with Link.

Example:

Example2 expressions
-- /post#TRACKINGtype MyApi = "post" :> Fragment Text :> Get '[JSON] Tracking
Instances5HasLink, HasServer, AtMostOneFragment, MkLink, ServerT
classclass FramingRender (strategy :: k) where
#

The FramingRender class provides the logic for emitting a framing strategy. The strategy transforms a SourceT m a into SourceT m ByteString, therefore it can prepend, append and intercalate framing structure around chunks.

Note: as the Monad m is generic, this is pure transformation.

Methods

Instances3FramingRender
classclass FramingUnrender (strategy :: k) where
#

The FramingUnrender class provides the logic for parsing a framing strategy.

Methods

Instances3FramingUnrender
classclass FromSourceIO chunk a | a -> chunk where
#

FromSourceIO is intended to be implemented for types such as Conduit, Pipe, etc. By implementing this class, all such streaming abstractions can be used directly on the client side for talking to streaming endpoints.

Methods

Instances1FromSourceIO
datadata Header' (mods :: [Type]) (sym :: Symbol) a
#
Instances9AddHeader, HasResponseHeader, HasLink, HasServer, BuildHeadersTo, GetHeaders', …
familytype family If (cond :: Bool) (tru :: k) (fls :: k) :: k where
#

Type-level If. If True a b ==> a; If False a b ==> b

Equations

datadata 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.

Constructors

  • Secure

    the connection to the server is secure (HTTPS)

  • NotSecure

    the connection to the server is not secure (HTTP)

Instances10Eq, Ord, Read, Show, Generic, HasLink, …
datadata NoContentVerb (method :: k1)
#

NoContentVerb is a specific type to represent NoContent responses. It does not require either a list of content types (because there's no content) or a status code (because it should always be 204).

Instances6HasLink, HasServer, Generic, Rep, MkLink, ServerT
datadata QueryFlag (sym :: Symbol)
#

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:

Example2 expressions
-- /books?publishedtype MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book]
Instances4HasLink, HasServer, MkLink, ServerT
  • (KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub)Defined in servant-0.20.2 · Servant.Links
  • (KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use QueryFlag "published" in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of type Bool.

    Example:

    type MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book]
    
    server :: Server MyApi
    server = getBooks
      where getBooks :: Bool -> Handler [Book]
            getBooks onlyPublished = ...return all books, or only the ones that are already published, depending on the argument...
  • type MkLink (QueryFlag sym :> sub) a = Bool -> MkLink sub aDefined in servant-0.20.2 · Servant.Links
  • type ServerT (QueryFlag sym :> api) m = Bool -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata QueryParam' (mods :: [Type]) (sym :: Symbol) a
#

QueryParam which can be Required, Lenient, or modified otherwise.

Instances4HasLink, HasServer, MkLink, ServerT
datadata QueryParams (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&param[]=val2 and so on. Note that servant doesn't actually require the []s and will fetch the values just fine with param=val1&param=val2, too.

Example:

Example2 expressions
-- /books?authors[]=<author1>&authors[]=<author2>&...type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book]
Instances4HasLink, HasServer, MkLink, ServerT
  • (KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub)Defined in servant-0.20.2 · Servant.Links
  • (KnownSymbol sym, FromHttpApiData a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (QueryParams sym a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use QueryParams "authors" Text in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of type [Text].

    This lets servant worry about looking up 0 or more values in the query string associated to authors and turning each of them into a value of the type you specify.

    You can control how the individual values are converted from Text to your type by simply providing an instance of FromHttpApiData for your type.

    Example:

    type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book]
    
    server :: Server MyApi
    server = getBooksBy
      where getBooksBy :: [Text] -> Handler [Book]
            getBooksBy authors = ...return all books by these authors...
  • type MkLink (QueryParams sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.2 · Servant.Links
  • type ServerT (QueryParams sym a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata QueryString
#

Extract the whole query string from a request. This is useful for query strings containing dynamic parameter names. For query strings with static parameter names, QueryParam is more suited.

Example:

Example2 expressions
-- /books?author=<author name>&year=<book year>type MyApi = "books" :> QueryString :> Get '[JSON] [Book]
Instances2HasServer, ServerT
  • HasServer api context => HasServer (QueryString :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use QueryString in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of type Query ([(ByteString, Maybe ByteString)]).

    This lets you extract the whole query string. This is useful when the query string can contain parameters with dynamic names, that you can't access with QueryParam.

    Example:

    type MyApi = "books" :> QueryString :> Get '[JSON] [Book]
    
    server :: Server MyApi
    server = getBooksBy
      where getBooksBy :: Query -> Handler [Book]
            getBooksBy filters = ...filter books based on the dynamic filters provided...
  • type ServerT (QueryString :> api) m = Query -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata 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 functions from Servant.Server.StaticFiles to serve static files stored in a particular directory on your filesystem

Instances4HasLink, HasServer, MkLink, ServerT
  • HasLink RawDefined in servant-0.20.2 · Servant.Links
  • HasServer Raw contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    Just pass the request to the underlying application and serve its response.

    Example:

    type MyApi = "images" :> Raw
    
    server :: Server MyApi
    server = serveDirectory "/var/www/images"
  • type MkLink Raw a = aDefined in servant-0.20.2 · Servant.Links
  • type ServerT Raw m = Tagged m ApplicationDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata RawM
#

Variant of Raw that lets you access the underlying monadic context to process the request.

Instances4HasLink, HasServer, MkLink, ServerT
  • HasLink RawMDefined in servant-0.20.2 · Servant.Links
  • HasServer RawM contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    Just pass the request to the underlying application and serve its response.

    Example:

    type MyApi = "images" :> Raw
    
    server :: Server MyApi
    server = serveDirectory "/var/www/images"
  • type MkLink RawM a = aDefined in servant-0.20.2 · Servant.Links
  • type ServerT RawM m = Request -> (Response -> IO ResponseReceived) -> m ResponseReceivedDefined in servant-server-0.20.2 · Servant.Server.Internal
classclass ReflectMethod (a :: k) where
#

Methods

Instances9ReflectMethod, …
datadata RemoteHost
#

Provides access to the host or IP address from which the HTTP request was sent.

Instances4HasLink, HasServer, MkLink, ServerT
datadata ReqBody' (mods :: [Type]) (contentTypes :: [Type]) a
#

Note: ReqBody' is always Required.

Instances4HasLink, HasServer, MkLink, ServerT
  • HasLink sub => HasLink (ReqBody' mods ct a :> sub)Defined in servant-0.20.2 · Servant.Links
  • (AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (ReqBody' mods list a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use ReqBody in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of the type specified by ReqBody. The Content-Type header is inspected, and the list provided is used to attempt deserialization. If the request does not have a Content-Type header, it is treated as application/octet-stream (as specified in RFC 7231 section 3.1.1.5). This lets servant worry about extracting it from the request and turning it into a value of the type you specify.

    All it asks is for a FromJSON instance.

    Example:

    type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
    
    server :: Server MyApi
    server = postBook
      where postBook :: Book -> Handler Book
            postBook book = ...insert into your db...
  • type MkLink (ReqBody' mods ct a :> sub) r = MkLink sub rDefined in servant-0.20.2 · Servant.Links
  • type ServerT (ReqBody' mods list a :> api) m = If (FoldLenient mods) (Either String a) a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata SBool (b :: Bool) where
#

Constructors

Instances12EqP, GCompare, GEq, GNFData, GRead, GShow, …
  • EqP SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • GCompare SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • GEq SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
    Example1 expression
    geq STrue STrueJust Refl
    Example1 expression
    geq STrue SFalseNothing
  • GNFData SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • GRead SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
    Example1 expression
    readsPrec 0 "Some STrue" :: [(Some SBool, String)][(Some STrue,"")]
    Example1 expression
    readsPrec 0 "Some SFalse" :: [(Some SBool, String)][(Some SFalse,"")]
    Example1 expression
    readsPrec 0 "Some Else" :: [(Some SBool, String)][]
  • GShow SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
    Example1 expression
    showsPrec 0 STrue """STrue"
  • OrdP SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • Eq (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • Ord (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • Show (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • NFData (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • SBoolI b => Boring (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.Bool
classclass SBoolI (b :: Bool) where
#

Methods

Instances2SBoolI
  • SBoolI 'FalseDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
  • SBoolI 'TrueDefined in singleton-bool-0.1.8 · Data.Singletons.Bool
typetype SourceIO = SourceT IO
#

Stream endpoints may be implemented as producing a SourceIO chunk.

Clients reading from streaming endpoints can be implemented as consuming a SourceIO chunk.

datadata Stream (method :: k1) (status :: Nat) framing contentType a
#

A Stream endpoint for a given method emits a stream of encoded values at a given Content-Type, delimited by a framing strategy. Type synonyms are provided for standard methods.

Instances8HasLink, HasServer, Generic, Rep, MkLink, ServerT, …
datadata StreamBody' (mods :: [Type]) framing contentType a
#
Instances6HasLink, HasServer, Generic, Rep, MkLink, ServerT
datadata Summary (sym :: Symbol)
#

Add a short summary for (part of) API.

Example:

Example1 expression
type MyApi = Summary "Get book by ISBN." :> "books" :> Capture "isbn" Text :> Get '[JSON] Book
Instances4HasLink, HasServer, MkLink, ServerT
classclass ToSourceIO chunk a | a -> chunk where
#

ToSourceIO is intended to be implemented for types such as Conduit, Pipe, etc. By implementing this class, all such streaming abstractions can be used directly as endpoints.

Methods

Instances3ToSourceIO
typetype Vault = Vault RealWorld
#

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.

Instances4HasLink, HasServer, MkLink, ServerT
datadata Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [Type]) a
#

Verb is a general type for representing HTTP verbs (a.k.a. methods). For convenience, type synonyms for each verb with a 200 response code are provided, but you are free to define your own:

Example1 expression
type Post204 contentTypes a = Verb 'POST 204 contentTypes a
Instances9HasLink, HasServer, Generic, AtMostOneFragment, Rep, MkLink, …
datadata WithNamedContext (name :: Symbol) (subContext :: [Type]) (subApi :: k)
#

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.

Instances4HasLink, HasServer, MkLink, ServerT
datadata WithResource (res :: k)
#
Instances4HasLink, HasServer, MkLink, ServerT
  • HasLink sub => HasLink (WithResource res :> sub)Defined in servant-0.20.2 · Servant.Links
  • (HasServer api ctx, HasContextEntry ctx (Acquire a)) => HasServer (WithResource a :> api) ctxDefined in servant-server-0.20.2 · Servant.Server.Internal

    If you use WithResource in one of the endpoints for your API Servant will provide the handler for this endpoint an argument of the specified type. The lifespan of this resource will be automatically managed by Servant. This resource will be created before the handler starts and it will be destoyed after it ends. A new resource is created for each request to the endpoint.

  • type MkLink (WithResource res :> sub) a = MkLink sub aDefined in servant-0.20.2 · Servant.Links
  • type ServerT (WithResource a :> api) m = (ReleaseKey, a) -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata NamedRoutes (api :: Type -> Type)
#

Combinator for embedding a record of named routes into a Servant API type.

Instances4HasLink, HasServer, MkLink, ServerT
classclass GenericMode (mode :: k) where
#

A class with a type family that applies an appropriate type family to the api parameter. For example, AsApi will leave api untouched, while AsServerT m will produce ServerT api m.

Associated types

  • type family (:-) (mode :: k) api
Instances3GenericMode
typetype ToServant (routes :: k -> Type) (mode :: k) = GToServant (Rep (routes mode))
#

Turns a generic product type into a tree of :<|> combinators.

valuefromServant
  1. :: GenericServant routes mode
  2. => ToServant routes mode
  3. -> routes mode
#

Inverse of toServant.

This can be used to turn generated values such as client functions into records.

You may need to provide a type signature for the output type (your record type).

classclass Accept ctype => MimeRender (ctype :: k) a where
#

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

Methods

Instances11MimeRender, …
classclass Accept ctype => MimeUnrender (ctype :: k) a where
#

Instantiate this class to register a way of deserializing a type based on the request's Content-Type header.

Example3 expressions
import Network.HTTP.Media hiding (Accept)import qualified Data.ByteString.Lazy.Char8 as BSCdata MyContentType = MyContentType String
Example1 expression
:{instance Accept MyContentType where   contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8"):}
Example1 expression
:{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":}
Example1 expression
type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int

Methods

Instances11MimeUnrender, …
datadata NoContent
#

A type for responses without content-body.

Instances10Eq, Read, Show, Generic, NFData, HasStatus, …
datadata Headers (ls :: [Type]) a
#

Response Header objects. You should never need to construct one directly. Instead, use addOptionalHeader.

Constructors

Instances11AddHeader, IsServerResource, HasServer, Functor, NFData, GetHeaders, …
classclass FromHttpApiData a where
#

Parse value from HTTP API data.

WARNING: Do not derive this using DeriveAnyClass as the generated instance will loop indefinitely.

Methods

Instances53FromHttpApiData, …
typetype Capture = Capture' '[]
#

Capture a value from the request path under a certain type a.

Example:

Example2 expressions
-- GET /books/:isbntype MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
typetype ReqBody = ReqBody' '[Required, Strict]
#

Extract the request body as a value of type a.

Example:

Example2 expressions
-- POST /bookstype MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
classclass KnownStatus (StatusOf a) => HasStatus a where
#

Associated types

Instances3HasStatus
  • HasStatus NoContentDefined in servant-0.20.2 · Servant.API.UVerb

    If an API can respond with NoContent we assume that this will happen with the status code 204 No Content. If this needs to be overridden, WithStatus can be used.

  • KnownStatus n => HasStatus (WithStatus n a)Defined in servant-0.20.2 · Servant.API.UVerb

    an instance of this typeclass assigns a HTTP status code to a return type

    Example:

       data NotFoundError = NotFoundError String
    
       instance HasStatus NotFoundError where
         type StatusOf NotFoundError = 404
    

    You can also use the convience newtype wrapper WithStatus if you want to avoid writing a HasStatus instance manually. It also has the benefit of showing the status code in the type; which might aid in readability.

  • HasStatus a => HasStatus (Headers ls a)Defined in servant-0.20.2 · Servant.API.UVerb
typetype IsMember (a :: u) (as :: [u]) = (Unique as, CheckElemIsMember a as, UElem a as)
#
familytype family Statuses (as :: [Type]) :: [Nat]
#
Instances2Statuses
  • type Statuses '[] = '[]Defined in servant-0.20.2 · Servant.API.UVerb
  • type Statuses (a ': as) = StatusOf a ': Statuses asDefined in servant-0.20.2 · Servant.API.UVerb
familytype family Statuses (as :: [Type]) :: [Nat]
#
Instances2Statuses
  • type Statuses '[] = '[]Defined in servant-0.20.2 · Servant.API.UVerb
  • type Statuses (a ': as) = StatusOf a ': Statuses asDefined in servant-0.20.2 · Servant.API.UVerb
familytype family Unique (xs :: [k]) :: Constraint where
#

Check whether all values in a type-level list are distinct. This will throw a nice error if there are any duplicate elements in the list.

Equations

newtypenewtype WithStatus (k :: Nat) a
#

A simple newtype wrapper that pairs a type with its status code. It implements all the content types that Servant ships with by default.

Constructors

Instances13MimeRender, MimeUnrender, IsServerResource, Eq, Show, HasStatus, …
datadata StdMethod
#

HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).

Instances19Bounded, Enum, Eq, Data, Ord, Read, …
datadata HttpVersion
#

HTTP Version.

Note that the Show instance is intended merely for debugging.

Instances10Eq, Data, Ord, Show, Generic, HasLink, …
datadata FormUrlEncoded
#
Instances5Accept, MimeRender, MimeUnrender
datadata JSON
#
Instances5Accept, MimeRender, MimeUnrender
datadata OctetStream
#
Instances7Accept, MimeRender, MimeUnrender, …
datadata PlainText
#
Instances9Accept, MimeRender, MimeUnrender, …
datadata AuthProtect (tag :: k)
#

A generalized Authentication combinator. Use this if you have a non-standard authentication technique.

NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE.

Instances4HasLink, HasServer, MkLink, ServerT
familytype family (:-) (mode :: k) api
#
Instances3:-
  • type (:-) AsApi api = apiDefined in servant-0.20.2 · Servant.API.Generic
  • type (:-) (AsLink a) api = MkLink api aDefined in servant-0.20.2 · Servant.Links
  • type (:-) (AsServerT m) api = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
datadata AsApi
#

A type that specifies that an API record contains an API definition. Only useful at type-level.

Instances2GenericMode, :-
  • GenericMode AsApiDefined in servant-0.20.2 · Servant.API.Generic
  • type (:-) AsApi api = apiDefined in servant-0.20.2 · Servant.API.Generic
datadata Lenient
#

Leniently parsed argument, i.e. parsing never fail. Wrapped in Either Text.

datadata Required
#

Required argument. Not wrapped.

datadata Strict
#

Strictly parsed argument. Not wrapped.

Lookup the value associated to the sym query string parameter and try to extract it as a value of type a.

Example:

Example2 expressions
-- /books?author=<author name>type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]
classclass AddHeader (mods :: [Type]) (h :: Symbol) v orig new | mods h v orig -> new, new -> mods, new -> h, new -> v, new -> orig where
#
Instances4AddHeader
valueaddHeader :: AddHeader '[Optional, Strict] h v orig new => v -> orig -> new
#

addHeader adds a header to a response. Note that it changes the type of the value in the following ways:

  1. A simple value is wrapped in "Headers '[hdr]":

Example2 expressions
let example0 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;getHeaders example0[("someheader","5")]
  1. A value that already has a header has its new header *prepended* to the existing list:

Example3 expressions
let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;let example2 = addHeader True example1 :: Headers '[Header "1st" Bool, Header "someheader" Int] StringgetHeaders example2[("1st","true"),("someheader","5")]

Note that while in your handlers type annotations are not required, since the type can be inferred from the API type, in other cases you may find yourself needing to add annotations.

valuelookupResponseHeader
  1. :: HasResponseHeader h a headers
  2. => Headers headers r
  3. -> ResponseHeader h a
#

Look up a specific ResponseHeader, without having to know what position it is in the HList.

Example3 expressions
let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] Stringlet example2 = addHeader True example1 :: Headers '[Header "1st" Bool, Header "someheader" Int] StringlookupResponseHeader example2 :: ResponseHeader "someheader" IntHeader 5
Example1 expression
lookupResponseHeader example2 :: ResponseHeader "1st" BoolHeader True

Usage of this function relies on an explicit type annotation of the header to be looked up. This can be done with type annotations on the result, or with an explicit type application. In this example, the type of header value is determined by the type-inference, we only specify the name of the header:

Example2 expressions
:set -XTypeApplicationscase lookupResponseHeader @"1st" example2 of { Header b -> b ; _ -> False }True
valuenoHeader :: AddHeader '[Optional, Strict] h v orig new => orig -> new
#

Deliberately do not add a header to a value.

Example2 expressions
let example1 = noHeader "hi" :: Headers '[Header "someheader" Int] StringgetHeaders example1[]
datadata NetstringFraming
#

The netstring framing strategy as defined by djb: http://cr.yp.to/proto/netstrings.txt

Any string of 8-bit bytes may be encoded as [len]":"[string]",". Here [string] is the string and [len] is a nonempty sequence of ASCII digits giving the length of [string] in decimal. The ASCII digits are 30 for 0, 31 for 1, and so on up through 39 for 9. Extra zeros at the front of [len] are prohibited: [len] begins with 30 exactly when [string] is empty.

For example, the string "hello world!" is encoded as 32 3a 68 65 6c 6c 6f 20 77 6f 72 6c 64 21 2c, i.e., "12:hello world!,". The empty string is encoded as "0:,".

Instances2FramingRender, FramingUnrender
datadata NewlineFraming
#

A simple framing strategy that has no header, and inserts a newline character after each frame. This assumes that it is used with a Content-Type that encodes without newlines (e.g. JSON).

Instances2FramingRender, FramingUnrender
datadata NoFraming
#

A framing strategy that does not do any framing at all, it just passes the input data This will be used most of the time with binary data, such as files

Instances2FramingRender, FramingUnrender
  • FramingRender NoFramingDefined in servant-0.20.2 · Servant.API.Stream
  • FramingUnrender NoFramingDefined in servant-0.20.2 · Servant.API.Stream

    As NoFraming doesn't have frame separators, we take the chunks as given and try to convert them one by one.

    That works well when a is a ByteString.

familytype family IsElem endpoint api :: Constraint where
#

Closed type family, check if endpoint is within api. Uses IsElem' if it exhausts all other options.

Example1 expression
ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))OK
Example1 expression
ok (Proxy :: Proxy (IsElem ("bye" :> Get '[JSON] Int) SampleAPI))...... Could not ......

An endpoint is considered within an api even if it is missing combinators that don't affect the URL:

Example1 expression
ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))OK
Example1 expression
ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (ReqBody '[JSON] Bool :> Get '[JSON] Int)))OK
  • N.B.:* IsElem a b can be seen as capturing the notion of whether the URL represented by a would match the URL represented by b, *not* whether a request represented by a matches the endpoints serving b (for the latter, use IsIn).

Equations

familytype family IsElem' a s :: Constraint
#

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.

Example2 expressions
data CustomThingtype 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.

classclass ToHttpApiData a where
#

Convert value to HTTP API data.

WARNING: Do not derive this using DeriveAnyClass as the generated instance will loop indefinitely.

Methods

Instances53ToHttpApiData, …
  • ToHttpApiData SetCookieDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData

    Note: this instance works correctly for alphanumeric name and value

    Example2 expressions
    let Right c = parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookietoUrlPiece c"SESSID=r2t5uvjq435r4q7ib3vtdjq120"
    Example1 expression
    toHeader c"SESSID=r2t5uvjq435r4q7ib3vtdjq120"
  • ToHttpApiData IntegerDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData NaturalDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData StringDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData VoidDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData AllDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData AnyDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData VersionDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece (Version [1, 2, 3] [])"1.2.3"
  • ToHttpApiData Int16Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Int32Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Int64Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Int8Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Word16Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Word32Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Word64Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData Word8Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData BoolDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData CharDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData DoubleDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData FloatDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData IntDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData OrderingDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData WordDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData LinkDefined in servant-0.20.2 · Servant.Links
  • ToHttpApiData TextDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData TextDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData DayDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece (fromGregorian 2015 10 03)"2015-10-03"
  • ToHttpApiData MonthDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example2 expressions
    import Data.Time.Calendar.Month.Compat (Month (..))MkMonth 244822040-03
    Example1 expression
    toUrlPiece $ MkMonth 24482"2040-03"
  • ToHttpApiData QuarterDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example2 expressions
    import Data.Time.Calendar.Quarter.Compat (Quarter (..))MkQuarter 80402010-Q1
    Example1 expression
    toUrlPiece $ MkQuarter 8040"2010-q1"
  • ToHttpApiData QuarterOfYearDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece Q4"q4"
  • ToHttpApiData DayOfWeekDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece Monday"monday"
  • ToHttpApiData NominalDiffTimeDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData UTCTimeDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece $ UTCTime (fromGregorian 2015 10 03) 864.5"2015-10-03T00:14:24.500Z"
  • ToHttpApiData LocalTimeDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece $ LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 21.687)"2015-10-03T14:55:21.687"
  • ToHttpApiData TimeOfDayDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece $ TimeOfDay 14 55 23.1"14:55:23.100"
  • ToHttpApiData ZonedTimeDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece $ ZonedTime (LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 51.001)) utc"2015-10-03T14:55:51.001Z"
    Example1 expression
    toUrlPiece $ ZonedTime (LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 51.001)) (TimeZone 120 True "EET")"2015-10-03T14:55:51.001+02:00"
  • ToHttpApiData UUIDDefined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData ()Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece ()"_"
  • ToHttpApiData a => ToHttpApiData (First a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Last a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Max a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Min a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Identity a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (First a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Last a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Dual a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Product a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Sum a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Maybe a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example1 expression
    toUrlPiece (Just "Hello")"just Hello"
  • HasResolution a => ToHttpApiData (Fixed a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData

    Note: this instance is not polykinded

  • (ToHttpApiData a, ToHttpApiData b) => ToHttpApiData (Either a b)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
    Example2 expressions
    toUrlPiece (Left "err" :: Either String Int)"left err"toUrlPiece (Right 3 :: Either String Int)"right 3"
  • ToHttpApiData a => ToHttpApiData (Const a b)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData
  • ToHttpApiData a => ToHttpApiData (Tagged b a)Defined in http-api-data-0.6.1 · Web.Internal.HttpApiData

    Note: this instance is not polykinded

datadata URI
#

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:

Constructors

Instances12Eq, Data, Ord, Show, Generic, NFData, …

For implementing servers for servant APIs.

Utilities on top of the servant core

classclass FragmentUnique api => AtMostOneFragment api
#

If there is more than one fragment in an API endpoint, a compile-time error is raised.

Example2 expressions
type FailAPI = Fragment Bool :> Fragment Int :> Get '[JSON] NoContentinstance AtMostOneFragment FailAPI......Only one Fragment allowed per endpoint in api......
Instances3AtMostOneFragment
familytype family IsElem endpoint api :: Constraint where
#

Closed type family, check if endpoint is within api. Uses IsElem' if it exhausts all other options.

Example1 expression
ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))OK
Example1 expression
ok (Proxy :: Proxy (IsElem ("bye" :> Get '[JSON] Int) SampleAPI))...... Could not ......

An endpoint is considered within an api even if it is missing combinators that don't affect the URL:

Example1 expression
ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))OK
Example1 expression
ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (ReqBody '[JSON] Bool :> Get '[JSON] Int)))OK
  • N.B.:* IsElem a b can be seen as capturing the notion of whether the URL represented by a would match the URL represented by b, *not* whether a request represented by a matches the endpoints serving b (for the latter, use IsIn).

Equations

familytype family IsElem' a s :: Constraint
#

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.

Example2 expressions
data CustomThingtype 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.

datadata URI
#

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:

Constructors

Instances12Eq, Data, Ord, Show, Generic, NFData, …
typetype Elem (e :: t) (es :: [t]) = ElemGo e es es
#

Check that a value is an element of a list:

Example1 expression
ok (Proxy :: Proxy (Elem Bool '[Int, Bool]))OK
Example1 expression
ok (Proxy :: Proxy (Elem String '[Int, Bool]))...... [Char]...'[Int, Bool......
familytype family AllIsIn (xs :: [Type]) api :: Constraint where
#

Check that every element of xs is an endpoint of api (using IsIn).

Example1 expression
ok (Proxy :: Proxy (AllIsIn (Endpoints SampleAPI) SampleAPI))OK

Equations

familytype family IsIn endpoint api :: Constraint where
#

Closed type family, check if endpoint is exactly within api.

Example1 expression
ok (Proxy :: Proxy (IsIn ("hello" :> Get '[JSON] Int) SampleAPI))OK

Unlike IsElem, this requires an *exact* match.

Example1 expression
ok (Proxy :: Proxy (IsIn (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))...... Could not ......

Equations

familytype family IsSubAPI sub api :: Constraint where
#

Check whether sub is a sub-API of api.

Example1 expression
ok (Proxy :: Proxy (IsSubAPI SampleAPI (SampleAPI :<|> Get '[JSON] Int)))OK
Example1 expression
ok (Proxy :: Proxy (IsSubAPI (SampleAPI :<|> Get '[JSON] Int) SampleAPI))...... Could not ......

This uses IsElem for checking; thus the note there applies here.

Equations

familytype family Or (a :: Constraint) (b :: Constraint) :: Constraint where
#

If either a or b produce an empty constraint, produce an empty constraint.

Equations

  • Or () b = ()
  • Or a () = ()

How to encode array query elements.

Constructors

Instances5Bounded, Enum, Eq, Ord, Show
valuelinkURI :: Link -> URI
#

Transform Link into URI.

Example2 expressions
type API = "something" :> Get '[JSON] IntlinkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API)something
Example2 expressions
type API = "sum" :> QueryParams "x" Int :> Get '[JSON] IntlinkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API) [1, 2, 3]sum?x[]=1&x[]=2&x[]=3
Example2 expressions
type API = "foo/bar" :> Get '[JSON] IntlinkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API)foo%2Fbar
Example3 expressions
type SomeRoute = "abc" :> Capture "email" String :> Put '[JSON] ()let someRoute = Proxy :: Proxy SomeRoutesafeLink someRoute someRoute "test@example.com"Link {_segments = ["abc","test%40example.com"], _queryParams = [], _fragment = Nothing}
Example1 expression
linkURI $ safeLink someRoute someRoute "test@example.com"abc/test%40example.com

Configurable linkURI.

Example2 expressions
type API = "sum" :> QueryParams "x" Int :> Get '[JSON] IntlinkURI' LinkArrayElementBracket $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API) [1, 2, 3]sum?x[]=1&x[]=2&x[]=3
Example1 expression
linkURI' LinkArrayElementPlain $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API) [1, 2, 3]sum?x=1&x=2&x=3

Useful re-exports

datadata Proxy (t :: k)
#

Proxy is a type that holds no data, but has a phantom parameter of arbitrary type (or even kind). Its use is to provide type information, even though there is no value available of that type (or it may be too costly to create one).

Historically, Proxy :: Proxy a is a safer alternative to the undefined :: a idiom.

Example1 expression
Proxy :: Proxy (Void, Int -> Int)Proxy

Proxy can even hold types of higher kinds,

Example1 expression
Proxy :: Proxy EitherProxy
Example1 expression
Proxy :: Proxy FunctorProxy
Example1 expression
Proxy :: Proxy complicatedStructureProxy
Instances66Generic1, FoldableWithIndex, FunctorWithIndex, TraversableWithIndex, RepeatWithIndex, SemialignWithIndex, …
  • Generic1 ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • FoldableWithIndex Void ProxyDefined in indexed-traversable-0.1.4 · WithIndex
  • FunctorWithIndex Void ProxyDefined in indexed-traversable-0.1.4 · WithIndex
  • TraversableWithIndex Void ProxyDefined in indexed-traversable-0.1.4 · WithIndex
  • RepeatWithIndex Void ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • SemialignWithIndex Void ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • ZipWithIndex Void ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • FilterableWithIndex Void ProxyDefined in witherable-0.5 · Witherable
  • WitherableWithIndex Void ProxyDefined in witherable-0.5 · Witherable
  • EqP ProxyDefined in some-1.0.6 · Data.EqP
  • OrdP ProxyDefined in some-1.0.6 · Data.OrdP
  • Monad ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Functor ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Applicative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Foldable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Foldable
  • Traversable ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Traversable
  • Alternative ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • MonadPlus ProxyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • MonadZip ProxyDefined in base-4.20.2.0 · Control.Monad.Zip
  • Eq1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Ord1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Read1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Show1 ProxyDefined in base-4.20.2.0 · Data.Functor.Classes
  • Contravariant ProxyDefined in base-4.20.2.0 · Data.Functor.Contravariant
  • NFData1 ProxyDefined in deepseq-1.5.0.0 · Control.DeepSeq
  • Hashable1 ProxyDefined in hashable-1.4.7.0 · Data.Hashable.Class
  • Distributive ProxyDefined in distributive-0.6.2.1 · Data.Distributive
  • Decidable ProxyDefined in contravariant-1.5.5 · Data.Functor.Contravariant.Divisible
  • Divisible ProxyDefined in contravariant-1.5.5 · Data.Functor.Contravariant.Divisible
  • Alt ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Alt
  • Apply ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Bind.Class
  • Bind ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Bind.Class
  • Extend ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Extend
  • Conclude ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Contravariant.Conclude
  • Decide ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Contravariant.Decide
  • Divise ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Contravariant.Divise
  • Plus ProxyDefined in semigroupoids-6.0.1 · Data.Functor.Plus
  • Align ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Semialign ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Unalign ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Repeat ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Unzip ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Zip ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Filterable ProxyDefined in witherable-0.5 · Witherable
  • Witherable ProxyDefined in witherable-0.5 · Witherable
  • FromJSON1 ProxyDefined in aeson-2.2.3.0 · Data.Aeson.Types.FromJSON
  • ToJSON1 ProxyDefined in aeson-2.2.3.0 · Data.Aeson.Types.ToJSON
  • Bounded (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Enum (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Eq (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Data t => Data (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Ord (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Read (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Show (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Ix (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Generic (Proxy t)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Monoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • NFData (Proxy a)Defined in deepseq-1.5.0.0 · Control.DeepSeq
  • Hashable (Proxy a)Defined in hashable-1.4.7.0 · Data.Hashable.Class
  • FromJSON (Proxy a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.FromJSON
  • ToJSON (Proxy a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.ToJSON
  • Default (Proxy a)Defined in data-default-0.8.0.1 · Data.Default.Internal
  • Boring (Proxy a)Defined in boring-0.2.2 · Data.Boring
  • type Rep (Proxy t) = D1 ('MetaData "Proxy" "GHC.Internal.Data.Proxy" "ghc-internal" 'False) (C1 ('MetaCons "Proxy" 'PrefixI 'False) U1)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • type Rep1 Proxy = D1 ('MetaData "Proxy" "GHC.Internal.Data.Proxy" "ghc-internal" 'False) (C1 ('MetaCons "Proxy" 'PrefixI 'False) U1)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
methodthrowError :: e -> m a
#

Is used within a monadic computation to begin exception processing.