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

Safe Haskell | None
Language | Haskell2010

Servant.Server.Internal

Synopsis

- type Server (api :: k) = ServerT api Handler
- class HasServer (api :: k) (context :: [Type]) where
  - type ServerT (api :: k) (m :: Type -> Type)
  - route :: Proxy api -> Context context -> Delayed env (Server api) -> Router env
  - hoistServerWithContext :: Proxy api -> Proxy context -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n
- data EmptyServer = EmptyServer
- emptyServer :: forall (m :: Type -> Type). ServerT EmptyAPI m
- getAcceptHeader :: Request -> AcceptHeader
- data AsServerT (m :: Type -> Type)
- type AsServer = AsServerT Handler
- type family ServerT (api :: k) (m :: Type -> Type)
- acceptCheck :: forall (list :: [Type]). AllMime list => Proxy list -> AcceptHeader -> DelayedIO ()
- allowedMethodHead :: Method -> Request -> Bool
- methodCheck :: Method -> Request -> DelayedIO ()
- allowedMethod :: Method -> Request -> Bool
- methodRouter :: forall (ctypes :: [Type]) a b env. AllCTRender ctypes a => (b -> ([(HeaderName, ByteString)], a)) -> Method -> Proxy ctypes -> Status -> Delayed env (Handler b) -> Router env
- noContentRouter :: Method -> Status -> Delayed env (Handler b) -> Router env
- streamRouter :: forall {k1} {k2} (ctype :: k1) a c chunk env (framing :: k2). (MimeRender ctype chunk, FramingRender framing, ToSourceIO chunk a) => (c -> ([(HeaderName, ByteString)], a)) -> Method -> Status -> Proxy framing -> Proxy ctype -> Delayed env (Handler c) -> Router env
- parseDeepParam :: (Text, Maybe Text) -> Either String ([Text], Maybe Text)
- ct_wildcard :: ByteString
- type HasServerArrowTypeError (a :: t) (b :: t1) = ((('Text "No instance HasServer (a -> b)." ':$$: 'Text "Maybe you have used '->' instead of ':>' between ") ':$$: 'ShowType a) ':$$: 'Text "and") ':$$: 'ShowType b
- type GServerConstraints (api :: Type -> Type) (m :: Type -> Type) = (ToServant api (AsServerT m) ~ ServerT (ToServantApi api) m, GServantProduct (Rep (api (AsServerT m))))
- class GServer (api :: Type -> Type) (m :: Type -> Type) where
  - gServerProof :: Dict (GServerConstraints api m)
- class HasAcceptCheck (cs :: k) where
  - acceptCheck' :: Proxy cs -> AcceptHeader -> DelayedIO ()
- module Servant.Server.Internal.BasicAuth
- module Servant.Server.Internal.Context
- module Servant.Server.Internal.Delayed
- module Servant.Server.Internal.DelayedIO
- module Servant.Server.Internal.ErrorFormatter
- module Servant.Server.Internal.Handler
- module Servant.Server.Internal.Router
- module Servant.Server.Internal.RouteResult
- module Servant.Server.Internal.RoutingApplication
- module Servant.Server.Internal.ServerError

# Documentation

type Server (api :: k) = ServerT api Handler Source #

class HasServer (api :: k) (context :: [Type]) where Source #

Associated Types

type ServerT (api :: k) (m :: Type -> Type) Source #

The type of a server for this API, given a monad to run effects in.

Note that the result kind is `*`, so it is not a monad transformer, unlike what the `T` in the name might suggest.

Methods

route :: Proxy api -> Context context -> Delayed env (Server api) -> Router env Source #

hoistServerWithContext :: Proxy api -> Proxy context -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n Source #

#### Instances

Instances details

HasServer EmptyAPI context Source #

The server for an `EmptyAPI` is `emptyServer`.

    type MyApi = "nothing" :> EmptyApi

    server :: Server MyApi
    server = emptyServer

Instance details

Defined in Servant.Server.Internal

Associated Types

type ServerT EmptyAPI m |
Instance details Defined in Servant.Server.Internal type ServerT EmptyAPI m = Tagged m EmptyServer

Methods

route :: Proxy EmptyAPI -> Context context -> Delayed env (Server EmptyAPI) -> Router env Source #

hoistServerWithContext :: Proxy EmptyAPI -> Proxy context -> (forall x. m x -> n x) -> ServerT EmptyAPI m -> ServerT EmptyAPI n Source #

HasServer Raw context Source #

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"

Instance details

Defined in Servant.Server.Internal

Associated Types

type ServerT Raw m |
Instance details Defined in Servant.Server.Internal type ServerT Raw m = Tagged m Application

Methods

route :: Proxy Raw -> Context context -> Delayed env (Server Raw) -> Router env Source #

hoistServerWithContext :: Proxy Raw -> Proxy context -> (forall x. m x -> n x) -> ServerT Raw m -> ServerT Raw n Source #

HasServer RawM context Source #

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"

Instance details

Defined in Servant.Server.Internal

Associated Types

type ServerT RawM m |
Instance details Defined in Servant.Server.Internal type ServerT RawM m = Request -> (Response -> IO ResponseReceived) -> m ResponseReceived

Methods

route :: Proxy RawM -> Context context -> Delayed env (Server RawM) -> Router env Source #

hoistServerWithContext :: Proxy RawM -> Proxy context -> (forall x. m x -> n x) -> ServerT RawM m -> ServerT RawM n Source #

(TypeError (NoInstanceFor (HasServer api context)) :: Constraint) => HasServer (api :: k) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy api -> Context context -> Delayed env (Server api) -> Router env Source # hoistServerWithContext :: Proxy api -> Proxy context -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n Source #
(HasServer (ToServantApi api) context, forall (m :: Type -> Type). Generic (api (AsServerT m)), forall (m :: Type -> Type). GServer api m, ErrorIfNoGeneric api) => HasServer (NamedRoutes api :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (NamedRoutes api) -> Context context -> Delayed env (Server (NamedRoutes api)) -> Router env Source # hoistServerWithContext :: Proxy (NamedRoutes api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (NamedRoutes api) m -> ServerT (NamedRoutes api) n Source #

(HasServer a context, HasServer b context) => HasServer (a :<|> b :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (a :<|> b) -> Context context -> Delayed env (Server (a :<|> b)) -> Router env Source # hoistServerWithContext :: Proxy (a :<|> b) -> Proxy context -> (forall x. m x -> n x) -> ServerT (a :<|> b) m -> ServerT (a :<|> b) n Source #
ReflectMethod method => HasServer (NoContentVerb method :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (NoContentVerb method) -> Context context -> Delayed env (Server (NoContentVerb method)) -> Router env Source # hoistServerWithContext :: Proxy (NoContentVerb method) -> Proxy context -> (forall x. m x -> n x) -> ServerT (NoContentVerb method) m -> ServerT (NoContentVerb method) n Source #

(TypeError (HasServerArrowTypeError a b) :: Constraint) => HasServer (a -> b :: Type) context Source #

This instance prevents from accidentally using `->` instead of `:>`

    >>> serve (Proxy :: Proxy (Capture "foo" Int -> Get '[JSON] Int)) (error "...")
    ...
    ...No instance HasServer (a -> b).
    ...Maybe you have used '->' instead of ':>' between
    ...Capture' '[] "foo" Int
    ...and
    ...Verb 'GET 200 '[JSON] Int
    ...

    >>> undefined :: Server (Capture "foo" Int -> Get '[JSON] Int)
    ...
    ...No instance HasServer (a -> b).
    ...Maybe you have used '->' instead of ':>' between
    ...Capture' '[] "foo" Int
    ...and
    ...Verb 'GET 200 '[JSON] Int
    ...

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (a -> b) -> Context context -> Delayed env (Server (a -> b)) -> Router env Source # hoistServerWithContext :: Proxy (a -> b) -> Proxy context -> (forall x. m x -> n x) -> ServerT (a -> b) m -> ServerT (a -> b) n Source #
(TypeError (PartialApplication (HasServer :: Type -> [Type] -> Constraint) arr) :: Constraint) => HasServer (arr :> sub :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (arr :> sub) -> Context context -> Delayed env (Server (arr :> sub)) -> Router env Source # hoistServerWithContext :: Proxy (arr :> sub) -> Proxy context -> (forall x. m x -> n x) -> ServerT (arr :> sub) m -> ServerT (arr :> sub) n Source #
(KnownSymbol path, HasServer api context) => HasServer (path :> api :: Type) context Source # | Make sure the incoming request starts with `"/path"`, strip it and pass the rest of the request path to `api`.
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (path :> api) -> Context context -> Delayed env (Server (path :> api)) -> Router env Source # hoistServerWithContext :: Proxy (path :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (path :> api) m -> ServerT (path :> api) n Source #
HasServer api context => HasServer (HttpVersion :> api :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (HttpVersion :> api) -> Context context -> Delayed env (Server (HttpVersion :> api)) -> Router env Source # hoistServerWithContext :: Proxy (HttpVersion :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (HttpVersion :> api) m -> ServerT (HttpVersion :> api) n Source #
(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api :: Type) context Source # | Basic Authentication
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (BasicAuth realm usr :> api) -> Context context -> Delayed env (Server (BasicAuth realm usr :> api)) -> Router env Source # hoistServerWithContext :: Proxy (BasicAuth realm usr :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (BasicAuth realm usr :> api) m -> ServerT (BasicAuth realm usr :> api) n Source #

(KnownSymbol capture, FromHttpApiData a, Typeable a, HasServer api context, SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Capture' mods capture a :> api :: Type) context Source #

If you use `Capture` 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 the `Capture`. This lets servant worry about getting it from the URL and turning it into a value of the type you specify.

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

Example:

    type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book

    server :: Server MyApi
    server = getBook
      where getBook :: Text -> Handler Book
            getBook isbn = ...

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (Capture' mods capture a :> api) -> Context context -> Delayed env (Server (Capture' mods capture a :> api)) -> Router env Source #

hoistServerWithContext :: Proxy (Capture' mods capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Capture' mods capture a :> api) m -> ServerT (Capture' mods capture a :> api) n Source #

(KnownSymbol capture, FromHttpApiData a, Typeable a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (CaptureAll capture a :> api :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (CaptureAll capture a :> api) -> Context context -> Delayed env (Server (CaptureAll capture a :> api)) -> Router env Source # hoistServerWithContext :: Proxy (CaptureAll capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (CaptureAll capture a :> api) m -> ServerT (CaptureAll capture a :> api) n Source #
HasServer api ctx => HasServer (Description desc :> api :: Type) ctx Source # | Ignore ``Description`` in server handlers.
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Description desc :> api) -> Context ctx -> Delayed env (Server (Description desc :> api)) -> Router env Source # hoistServerWithContext :: Proxy (Description desc :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (Description desc :> api) m -> ServerT (Description desc :> api) n Source #
HasServer api ctx => HasServer (Summary desc :> api :: Type) ctx Source # | Ignore ``Summary`` in server handlers.
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Summary desc :> api) -> Context ctx -> Delayed env (Server (Summary desc :> api)) -> Router env Source # hoistServerWithContext :: Proxy (Summary desc :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (Summary desc :> api) m -> ServerT (Summary desc :> api) n Source #
HasServer api context => HasServer (EmptyAPI :> api :: Type) context Source # | Ignore ``EmptyAPI`` as part of route in server handlers.
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (EmptyAPI :> api) -> Context context -> Delayed env (Server (EmptyAPI :> api)) -> Router env Source # hoistServerWithContext :: Proxy (EmptyAPI :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (EmptyAPI :> api) m -> ServerT (EmptyAPI :> api) n Source #
(HasServer api context, HasContextEntry context (AuthHandler Request (AuthServerData (AuthProtect tag)))) => HasServer (AuthProtect tag :> api :: Type) context Source # | Known orphan instance.
Instance details Defined in Servant.Server.Experimental.Auth Methods route :: Proxy (AuthProtect tag :> api) -> Context context -> Delayed env (Server (AuthProtect tag :> api)) -> Router env Source # hoistServerWithContext :: Proxy (AuthProtect tag :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (AuthProtect tag :> api) m -> ServerT (AuthProtect tag :> api) n Source #

(AtMostOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer api context) => HasServer (Fragment a1 :> api :: Type) context Source #

Ignore ``Fragment`` in server handlers. See https://ietf.org/rfc/rfc2616.html#section-15.1.3 for more details.

Example:

    type MyApi = "books" :> Fragment Text :> Get '[JSON] [Book]

    server :: Server MyApi
    server = getBooks
      where getBooks :: Handler [Book]
            getBooks = ...return all books...

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Fragment a1 :> api) -> Context context -> Delayed env (Server (Fragment a1 :> api)) -> Router env Source # hoistServerWithContext :: Proxy (Fragment a1 :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Fragment a1 :> api) m -> ServerT (Fragment a1 :> api) n Source #

(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Header' mods sym a :> api :: Type) context Source #

If you use `Header` 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 `Header`. 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 `FromHttpApiData` instance.

Example:

    newtype Referer = Referer Text
      deriving (Eq, Show, FromHttpApiData)

               -- GET /view-my-referer
    type MyApi = "view-my-referer" :> Header "Referer" Referer :> Get '[JSON] Referer

    server :: Server MyApi
    server = viewReferer
      where viewReferer :: Referer -> Handler referer
            viewReferer referer = return referer

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Header' mods sym a :> api) -> Context context -> Delayed env (Server (Header' mods sym a :> api)) -> Router env Source # hoistServerWithContext :: Proxy (Header' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Header' mods sym a :> api) m -> ServerT (Header' mods sym a :> api) n Source #
(KnownSymbol sym, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Host sym :> api :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Host sym :> api) -> Context context -> Delayed env (Server (Host sym :> api)) -> Router env Source # hoistServerWithContext :: Proxy (Host sym :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Host sym :> api) m -> ServerT (Host sym :> api) n Source #
HasServer api context => HasServer (IsSecure :> api :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (IsSecure :> api) -> Context context -> Delayed env (Server (IsSecure :> api)) -> Router env Source # hoistServerWithContext :: Proxy (IsSecure :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (IsSecure :> api) m -> ServerT (IsSecure :> api) n Source #

(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (QueryFlag sym :> api) -> Context context -> Delayed env (Server (QueryFlag sym :> api)) -> Router env Source # hoistServerWithContext :: Proxy (QueryFlag sym :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryFlag sym :> api) m -> ServerT (QueryFlag sym :> api) n Source #

(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (QueryParam' mods sym a :> api :: Type) context Source #

If you use ``QueryParam` "author" 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 ``Maybe` `Text``.

This lets servant worry about looking it up in the query string and turning it into a value of the type you specify, enclosed in `Maybe`, because it may not be there and servant would then hand you `Nothing`.

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

Example:

    type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]

    server :: Server MyApi
    server = getBooksBy
      where getBooksBy :: Maybe Text -> Handler [Book]
            getBooksBy Nothing       = ...return all books...
            getBooksBy (Just author) = ...return books by the given author...

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (QueryParam' mods sym a :> api) -> Context context -> Delayed env (Server (QueryParam' mods sym a :> api)) -> Router env Source #

hoistServerWithContext :: Proxy (QueryParam' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParam' mods sym a :> api) m -> ServerT (QueryParam' mods sym a :> api) n Source #

(KnownSymbol sym, FromHttpApiData a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (QueryParams sym a :> api :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (QueryParams sym a :> api) -> Context context -> Delayed env (Server (QueryParams sym a :> api)) -> Router env Source # hoistServerWithContext :: Proxy (QueryParams sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParams sym a :> api) m -> ServerT (QueryParams sym a :> api) n Source #

(KnownSymbol sym, FromDeepQuery a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (DeepQuery sym a :> api :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (DeepQuery sym a :> api) -> Context context -> Delayed env (Server (DeepQuery sym a :> api)) -> Router env Source # hoistServerWithContext :: Proxy (DeepQuery sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (DeepQuery sym a :> api) m -> ServerT (DeepQuery sym a :> api) n Source #

HasServer api context => HasServer (QueryString :> api :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (QueryString :> api) -> Context context -> Delayed env (Server (QueryString :> api)) -> Router env Source # hoistServerWithContext :: Proxy (QueryString :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryString :> api) m -> ServerT (QueryString :> api) n Source #
HasServer api context => HasServer (RemoteHost :> api :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (RemoteHost :> api) -> Context context -> Delayed env (Server (RemoteHost :> api)) -> Router env Source # hoistServerWithContext :: Proxy (RemoteHost :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (RemoteHost :> api) m -> ServerT (RemoteHost :> api) n Source #

(AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (ReqBody' mods list a :> api :: Type) context Source #

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

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (ReqBody' mods list a :> api) -> Context context -> Delayed env (Server (ReqBody' mods list a :> api)) -> Router env Source # hoistServerWithContext :: Proxy (ReqBody' mods list a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (ReqBody' mods list a :> api) m -> ServerT (ReqBody' mods list a :> api) n Source #
(FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk, HasServer api context) => HasServer (StreamBody' mods framing ctype a :> api :: Type) context Source # |

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (StreamBody' mods framing ctype a :> api) -> Context context -> Delayed env (Server (StreamBody' mods framing ctype a :> api)) -> Router env Source #

hoistServerWithContext :: Proxy (StreamBody' mods framing ctype a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (StreamBody' mods framing ctype a :> api) m -> ServerT (StreamBody' mods framing ctype a :> api) n Source #

(HasServer api ctx, HasContextEntry ctx (Acquire a)) => HasServer (WithResource a :> api :: Type) ctx Source #

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.

Instance details Defined in Servant.Server.Internal Methods route :: Proxy (WithResource a :> api) -> Context ctx -> Delayed env (Server (WithResource a :> api)) -> Router env Source # hoistServerWithContext :: Proxy (WithResource a :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (WithResource a :> api) m -> ServerT (WithResource a :> api) n Source #
HasServer api context => HasServer (Vault :> api :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Vault :> api) -> Context context -> Delayed env (Server (Vault :> api)) -> Router env Source # hoistServerWithContext :: Proxy (Vault :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Vault :> api) m -> ServerT (Vault :> api) n Source #
(TypeError (NoInstanceForSub (HasServer :: Type -> [Type] -> Constraint) ty) :: Constraint) => HasServer (ty :> sub :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (ty :> sub) -> Context context -> Delayed env (Server (ty :> sub)) -> Router env Source # hoistServerWithContext :: Proxy (ty :> sub) -> Proxy context -> (forall x. m x -> n x) -> ServerT (ty :> sub) m -> ServerT (ty :> sub) n Source #
(ReflectMethod method, AllMime contentTypes, All (IsServerResourceWithStatus contentTypes) as, Unique (Statuses as)) => HasServer (UVerb method contentTypes as :: Type) context Source # |

Instance details

Defined in Servant.Server.UVerb

Methods

route :: Proxy (UVerb method contentTypes as) -> Context context -> Delayed env (Server (UVerb method contentTypes as)) -> Router env Source #

hoistServerWithContext :: Proxy (UVerb method contentTypes as) -> Proxy context -> (forall x. m x -> n x) -> ServerT (UVerb method contentTypes as) m -> ServerT (UVerb method contentTypes as) n Source #

(HasContextEntry context (NamedContext name subContext), HasServer subApi subContext) => HasServer (WithNamedContext name subContext subApi :: Type) context Source # |

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (WithNamedContext name subContext subApi) -> Context context -> Delayed env (Server (WithNamedContext name subContext subApi)) -> Router env Source #

hoistServerWithContext :: Proxy (WithNamedContext name subContext subApi) -> Proxy context -> (forall x. m x -> n x) -> ServerT (WithNamedContext name subContext subApi) m -> ServerT (WithNamedContext name subContext subApi) n Source #

(HasAcceptCheck cs, ResponseListRender cs as, AsUnion as r, ReflectMethod method) => HasServer (MultiVerb method cs as r :: Type) ctx Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (MultiVerb method cs as r) -> Context ctx -> Delayed env (Server (MultiVerb method cs as r)) -> Router env Source # hoistServerWithContext :: Proxy (MultiVerb method cs as r) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (MultiVerb method cs as r) m -> ServerT (MultiVerb method cs as r) n Source #
(AllCTRender ctypes a, ReflectMethod method, KnownNat status, GetHeaders (Headers h a)) => HasServer (Verb method status ctypes (Headers h a) :: Type) context Source # |

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (Verb method status ctypes (Headers h a)) -> Context context -> Delayed env (Server (Verb method status ctypes (Headers h a))) -> Router env Source #

hoistServerWithContext :: Proxy (Verb method status ctypes (Headers h a)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes (Headers h a)) m -> ServerT (Verb method status ctypes (Headers h a)) n Source #

(AllCTRender ctypes a, ReflectMethod method, KnownNat status) => HasServer (Verb method status ctypes a :: Type) context Source # |
Instance details Defined in Servant.Server.Internal Methods route :: Proxy (Verb method status ctypes a) -> Context context -> Delayed env (Server (Verb method status ctypes a)) -> Router env Source # hoistServerWithContext :: Proxy (Verb method status ctypes a) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes a) m -> ServerT (Verb method status ctypes a) n Source #
(MimeRender ctype chunk, ReflectMethod method, KnownNat status, FramingRender framing, ToSourceIO chunk a, GetHeaders (Headers h a)) => HasServer (Stream method status framing ctype (Headers h a) :: Type) context Source # |

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (Stream method status framing ctype (Headers h a)) -> Context context -> Delayed env (Server (Stream method status framing ctype (Headers h a))) -> Router env Source #

hoistServerWithContext :: Proxy (Stream method status framing ctype (Headers h a)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype (Headers h a)) m -> ServerT (Stream method status framing ctype (Headers h a)) n Source #

(MimeRender ctype chunk, ReflectMethod method, KnownNat status, FramingRender framing, ToSourceIO chunk a) => HasServer (Stream method status framing ctype a :: Type) context Source # |

Instance details

Defined in Servant.Server.Internal

Methods

route :: Proxy (Stream method status framing ctype a) -> Context context -> Delayed env (Server (Stream method status framing ctype a)) -> Router env Source #

hoistServerWithContext :: Proxy (Stream method status framing ctype a) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype a) m -> ServerT (Stream method status framing ctype a) n Source #

data EmptyServer Source #

Singleton type representing a server that serves an empty API.

Constructors

EmptyServer |

#### Instances

Instances details

Bounded EmptyServer Source # |
Instance details Defined in Servant.Server.Internal Methods minBound :: EmptyServer Source # maxBound :: EmptyServer Source #
Enum EmptyServer Source # |

Instance details

Defined in Servant.Server.Internal

Methods

succ :: EmptyServer -> EmptyServer Source #

pred :: EmptyServer -> EmptyServer Source #

toEnum :: Int -> EmptyServer Source #

fromEnum :: EmptyServer -> Int Source #

enumFrom :: EmptyServer -> [EmptyServer] Source #

enumFromThen :: EmptyServer -> EmptyServer -> [EmptyServer] Source #

enumFromTo :: EmptyServer -> EmptyServer -> [EmptyServer] Source #

enumFromThenTo :: EmptyServer -> EmptyServer -> EmptyServer -> [EmptyServer] Source #

Show EmptyServer Source # |
Instance details Defined in Servant.Server.Internal Methods showsPrec :: Int -> EmptyServer -> ShowS Source # show :: EmptyServer -> String Source # showList :: [EmptyServer] -> ShowS Source #
Eq EmptyServer Source # |
Instance details Defined in Servant.Server.Internal Methods (==) :: EmptyServer -> EmptyServer -> Bool Source # (/=) :: EmptyServer -> EmptyServer -> Bool Source #

emptyServer :: forall (m :: Type -> Type). ServerT EmptyAPI m Source #

Server for `EmptyAPI`

getAcceptHeader :: Request -> AcceptHeader Source #

data AsServerT (m :: Type -> Type) Source #

A type that specifies that an API record contains a server implementation.

#### Instances

Instances details

GenericMode (AsServerT m :: Type) Source # |
Instance details Defined in Servant.Server.Internal
type (AsServerT m :: Type) :- api Source # |
Instance details Defined in Servant.Server.Internal type (AsServerT m :: Type) :- api = ServerT api m

type AsServer = AsServerT Handler Source #

type family ServerT (api :: k) (m :: Type -> Type) Source #

The type of a server for this API, given a monad to run effects in.

Note that the result kind is `*`, so it is not a monad transformer, unlike what the `T` in the name might suggest.

#### Instances

Instances details

type ServerT EmptyAPI m Source # |
Instance details Defined in Servant.Server.Internal type ServerT EmptyAPI m = Tagged m EmptyServer
type ServerT Raw m Source # |
Instance details Defined in Servant.Server.Internal type ServerT Raw m = Tagged m Application
type ServerT RawM m Source # |
Instance details Defined in Servant.Server.Internal type ServerT RawM m = Request -> (Response -> IO ResponseReceived) -> m ResponseReceived
type ServerT (NamedRoutes api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (NamedRoutes api :: Type) m = api (AsServerT m)
type ServerT (a :<|> b :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (a :<|> b :: Type) m = ServerT a m :<|> ServerT b m
type ServerT (NoContentVerb method :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (NoContentVerb method :: Type) m = m NoContent
type ServerT (a -> b :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (a -> b :: Type) m = TypeError (HasServerArrowTypeError a b) :: Type
type ServerT (arr :> sub :: Type) _1 Source # |
Instance details Defined in Servant.Server.Internal type ServerT (arr :> sub :: Type) _1 = TypeError (PartialApplication (HasServer :: Type -> [Type] -> Constraint) arr) :: Type
type ServerT (path :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (path :> api :: Type) m = ServerT api m
type ServerT (HttpVersion :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (HttpVersion :> api :: Type) m = HttpVersion -> ServerT api m
type ServerT (BasicAuth realm usr :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (BasicAuth realm usr :> api :: Type) m = usr -> ServerT api m
type ServerT (Capture' mods capture a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Capture' mods capture a :> api :: Type) m = If (FoldLenient mods) (Either String a) a -> ServerT api m
type ServerT (CaptureAll capture a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (CaptureAll capture a :> api :: Type) m = [a] -> ServerT api m
type ServerT (Description desc :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Description desc :> api :: Type) m = ServerT api m
type ServerT (Summary desc :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Summary desc :> api :: Type) m = ServerT api m
type ServerT (EmptyAPI :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (EmptyAPI :> api :: Type) m = ServerT api m
type ServerT (AuthProtect tag :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Experimental.Auth type ServerT (AuthProtect tag :> api :: Type) m = AuthServerData (AuthProtect tag) -> ServerT api m
type ServerT (Fragment a1 :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Fragment a1 :> api :: Type) m = ServerT api m
type ServerT (Header' mods sym a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Header' mods sym a :> api :: Type) m = RequestArgument mods a -> ServerT api m
type ServerT (Host sym :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Host sym :> api :: Type) m = ServerT api m
type ServerT (IsSecure :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (IsSecure :> api :: Type) m = IsSecure -> ServerT api m
type ServerT (QueryFlag sym :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (QueryFlag sym :> api :: Type) m = Bool -> ServerT api m
type ServerT (QueryParam' mods sym a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (QueryParam' mods sym a :> api :: Type) m = RequestArgument mods a -> ServerT api m
type ServerT (QueryParams sym a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (QueryParams sym a :> api :: Type) m = [a] -> ServerT api m
type ServerT (DeepQuery sym a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (DeepQuery sym a :> api :: Type) m = a -> ServerT api m
type ServerT (QueryString :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (QueryString :> api :: Type) m = Query -> ServerT api m
type ServerT (RemoteHost :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (RemoteHost :> api :: Type) m = SockAddr -> ServerT api m
type ServerT (ReqBody' mods list a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (ReqBody' mods list a :> api :: Type) m = If (FoldLenient mods) (Either String a) a -> ServerT api m
type ServerT (StreamBody' mods framing ctype a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (StreamBody' mods framing ctype a :> api :: Type) m = a -> ServerT api m
type ServerT (WithResource a :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (WithResource a :> api :: Type) m = (ReleaseKey, a) -> ServerT api m
type ServerT (Vault :> api :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Vault :> api :: Type) m = Vault -> ServerT api m
type ServerT (UVerb method contentTypes as :: Type) m Source # |
Instance details Defined in Servant.Server.UVerb type ServerT (UVerb method contentTypes as :: Type) m = m (Union as)
type ServerT (WithNamedContext name subContext subApi :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (WithNamedContext name subContext subApi :: Type) m = ServerT subApi m
type ServerT (MultiVerb method cs as r :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (MultiVerb method cs as r :: Type) m = m r
type ServerT (Verb method status ctypes (Headers h a) :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Verb method status ctypes (Headers h a) :: Type) m = m (Headers h a)
type ServerT (Verb method status ctypes a :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Verb method status ctypes a :: Type) m = m a
type ServerT (Stream method status framing ctype (Headers h a) :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Stream method status framing ctype (Headers h a) :: Type) m = m (Headers h a)
type ServerT (Stream method status framing ctype a :: Type) m Source # |
Instance details Defined in Servant.Server.Internal type ServerT (Stream method status framing ctype a :: Type) m = m a

acceptCheck :: forall (list :: [Type]). AllMime list => Proxy list -> AcceptHeader -> DelayedIO () Source #

allowedMethodHead :: Method -> Request -> Bool Source #

methodCheck :: Method -> Request -> DelayedIO () Source #

allowedMethod :: Method -> Request -> Bool Source #

methodRouter :: forall (ctypes :: [Type]) a b env. AllCTRender ctypes a => (b -> ([(HeaderName, ByteString)], a)) -> Method -> Proxy ctypes -> Status -> Delayed env (Handler b) -> Router env Source #

noContentRouter :: Method -> Status -> Delayed env (Handler b) -> Router env Source #

streamRouter :: forall {k1} {k2} (ctype :: k1) a c chunk env (framing :: k2). (MimeRender ctype chunk, FramingRender framing, ToSourceIO chunk a) => (c -> ([(HeaderName, ByteString)], a)) -> Method -> Status -> Proxy framing -> Proxy ctype -> Delayed env (Handler c) -> Router env Source #

parseDeepParam :: (Text, Maybe Text) -> Either String ([Text], Maybe Text) Source #

ct_wildcard :: ByteString Source #

type HasServerArrowTypeError (a :: t) (b :: t1) = ((('Text "No instance HasServer (a -> b)." ':$$: 'Text "Maybe you have used '->' instead of ':>' between ") ':$$: 'ShowType a) ':$$: 'Text "and") ':$$: 'ShowType b Source #

type GServerConstraints (api :: Type -> Type) (m :: Type -> Type) = (ToServant api (AsServerT m) ~ ServerT (ToServantApi api) m, GServantProduct (Rep (api (AsServerT m)))) Source #

Set of constraints required to convert to / from vanilla server types.

class GServer (api :: Type -> Type) (m :: Type -> Type) where Source #

This class is a necessary evil: in the implementation of `HasServer` for ``NamedRoutes` api`, we essentially need the quantified constraint `forall m. `GServerConstraints` m` to hold.

We cannot require do that directly as the definition of `GServerConstraints` contains type family applications (`Rep` and `ServerT`). The trick is to hide those type family applications behind a typeclass providing evidence for ``GServerConstraints` api m` in the form of a dictionary, and require that `forall m. `GServer` api m` instead.

Users shouldn't have to worry about this class, as the only possible instance is provided in this module for all record APIs.

Methods

gServerProof :: Dict (GServerConstraints api m) Source #

#### Instances

Instances details

(ToServant api (AsServerT m) ~ ServerT (ToServantApi api) m, GServantProduct (Rep (api (AsServerT m)))) => GServer api m Source # |
Instance details Defined in Servant.Server.Internal Methods gServerProof :: Dict (GServerConstraints api m) Source #

class HasAcceptCheck (cs :: k) where Source #

Methods

acceptCheck' :: Proxy cs -> AcceptHeader -> DelayedIO () Source #

#### Instances

Instances details

HasAcceptCheck '() Source # |
Instance details Defined in Servant.Server.Internal Methods acceptCheck' :: Proxy '() -> AcceptHeader -> DelayedIO () Source #
AllMime cs => HasAcceptCheck (cs :: [Type]) Source # |
Instance details Defined in Servant.Server.Internal Methods acceptCheck' :: Proxy cs -> AcceptHeader -> DelayedIO () Source #

module Servant.Server.Internal.BasicAuth

module Servant.Server.Internal.Context

module Servant.Server.Internal.Delayed

module Servant.Server.Internal.DelayedIO

module Servant.Server.Internal.ErrorFormatter

module Servant.Server.Internal.Handler

module Servant.Server.Internal.Router

module Servant.Server.Internal.RouteResult

module Servant.Server.Internal.RoutingApplication

module Servant.Server.Internal.ServerError