Moduleservant-server-0.20.2Haskell2010
Servant.Server.Internal
- 6 types
- 2 classes
- 11 values
- Packageservant-server-0.20.2
- Exports20
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceInternal.hs
Associated types
Instances38HasServer, …
TypeError (NoInstanceFor (HasServer api context)) => HasServer api contextDefined in servant-server-0.20.2 · Servant.Server.InternalHasServer EmptyAPI contextDefined in servant-server-0.20.2 · Servant.Server.InternalThe server for an EmptyAPI is emptyServer.
type MyApi = "nothing" :> EmptyApi server :: Server MyApi server = emptyServerHasServer Raw contextDefined in servant-server-0.20.2 · Servant.Server.InternalJust pass the request to the underlying application and serve its response.
Example:
type MyApi = "images" :> Raw server :: Server MyApi server = serveDirectory "/var/www/images"HasServer RawM contextDefined in servant-server-0.20.2 · Servant.Server.InternalJust pass the request to the underlying application and serve its response.
Example:
type MyApi = "images" :> Raw server :: Server MyApi server = serveDirectory "/var/www/images"(HasServer (ToServantApi api) context, forall (m :: Type -> Type). Generic (api (AsServerT m)), forall (m :: Type -> Type). GServer api m, ErrorIfNoGeneric api) => HasServer (NamedRoutes api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalTypeError (HasServerArrowTypeError a b) => HasServer (a -> b) contextDefined in servant-server-0.20.2 · Servant.Server.InternalThis instance prevents from accidentally using
->instead of :>Example1 expression 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...
Example1 expression 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...
ReflectMethod method => HasServer (NoContentVerb method) contextDefined in servant-server-0.20.2 · Servant.Server.Internal(HasServer a context, HasServer b context) => HasServer (a :<|> b) contextDefined in servant-server-0.20.2 · Servant.Server.InternalA server for
a :<|> bfirst tries to match the request against the route represented byaand if it fails triesb. 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 = ...TypeError (NoInstanceForSub HasServer ty) => HasServer (ty :> sub) contextDefined in servant-server-0.20.2 · Servant.Server.InternalTypeError (PartialApplication HasServer arr) => HasServer (arr :> sub) contextDefined in servant-server-0.20.2 · Servant.Server.InternalHasServer api context => HasServer (HttpVersion :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalHasServer api context => HasServer (EmptyAPI :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIgnore
EmptyAPIas part of route in server handlers.HasServer api context => HasServer (IsSecure :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalHasServer api context => HasServer (QueryString :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIf you use
QueryStringin one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of typeQuery([().ByteString, MaybeByteString)]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
.QueryParamExample:
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...HasServer api context => HasServer (RemoteHost :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalHasServer api context => HasServer (Vault :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalHasServer api ctx => HasServer (Description desc :> api) ctxDefined in servant-server-0.20.2 · Servant.Server.InternalIgnore
Descriptionin server handlers.HasServer api ctx => HasServer (Summary desc :> api) ctxDefined in servant-server-0.20.2 · Servant.Server.InternalIgnore
Summaryin server handlers.(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.InternalIf 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 = ...(KnownSymbol capture, FromHttpApiData a, Typeable a, HasServer api context, SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Capture' mods capture a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIf you use
Capturein 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 theCapture. 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 = ...(KnownSymbol path, HasServer api context) => HasServer (path :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalMake sure the incoming request starts with
"/path", strip it and pass the rest of the request path toapi.(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalBasic Authentication
(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.InternalIf you use
QueryParams "authors" Textin 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
authorsand 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...(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Header' mods sym a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIf you use
Headerin 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 byHeader. 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(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods), HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (QueryParam' mods sym a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIf you use
in one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of typeQueryParam"author" TextMaybe 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...(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.InternalIf you use
DeepQuery "symbol" ain one of the endpoints for your API, this automatically requires your server-side handler to be a function that takes an argument of typea.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
(it can still be tedious if you the object has many fields). When some fields are dynamic, it cannot be done with @QueryParamQueryParam.The way the object is constructed from the extracted fields can be controlled by providing an instance on
FromDeepQueryExample:
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...(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIf 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...(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.InternalIf you use
ReqBodyin 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 byReqBody. TheContent-Typeheader is inspected, and the list provided is used to attempt deserialization. If the request does not have aContent-Typeheader, it is treated asapplication/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
FromJSONinstance.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...(FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk, HasServer api context) => HasServer (StreamBody' mods framing ctype a :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Internal(AtMostOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer api context) => HasServer (Fragment a1 :> api) contextDefined in servant-server-0.20.2 · Servant.Server.InternalIgnore
Fragmentin 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...(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(HasServer api context, HasContextEntry context (AuthHandler Request (AuthServerData (AuthProtect tag)))) => HasServer (AuthProtect tag :> api) contextDefined in servant-server-0.20.2 · Servant.Server.Experimental.Auth · orphanKnown orphan instance.
(HasServer api ctx, HasContextEntry ctx (Acquire a)) => HasServer (WithResource a :> api) ctxDefined in servant-server-0.20.2 · Servant.Server.InternalIf 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.
(HasContextEntry context (NamedContext name subContext), HasServer subApi subContext) => HasServer (WithNamedContext name subContext subApi) contextDefined in servant-server-0.20.2 · Servant.Server.Internal(AllCTRender ctypes a, ReflectMethod method, KnownNat status) => HasServer (Verb method status ctypes a) contextDefined in servant-server-0.20.2 · Servant.Server.Internal(AllCTRender ctypes a, ReflectMethod method, KnownNat status, GetHeaders (Headers h a)) => HasServer (Verb method status ctypes (Headers h a)) contextDefined in servant-server-0.20.2 · Servant.Server.Internal(MimeRender ctype chunk, ReflectMethod method, KnownNat status, FramingRender framing, ToSourceIO chunk a) => HasServer (Stream method status framing ctype a) contextDefined in servant-server-0.20.2 · Servant.Server.Internal(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)) contextDefined in servant-server-0.20.2 · Servant.Server.Internal
Singleton type representing a server that serves an empty API.
Instances4Bounded, Enum, Eq, Show
Bounded EmptyServerDefined in servant-server-0.20.2 · Servant.Server.InternalEnum EmptyServerDefined in servant-server-0.20.2 · Servant.Server.InternalEq EmptyServerDefined in servant-server-0.20.2 · Servant.Server.InternalShow EmptyServerDefined in servant-server-0.20.2 · Servant.Server.Internal
Server for EmptyAPI
A type that specifies that an API record contains a server implementation.
Instances2GenericMode, :-
GenericMode (AsServerT m)Defined in servant-server-0.20.2 · Servant.Server.Internaltype (:-) (AsServerT m) api = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
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.
Instances36ServerT, …
type ServerT EmptyAPI m = Tagged m EmptyServerDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT Raw m = Tagged m ApplicationDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT RawM m = Request -> (Response -> IO ResponseReceived) -> m ResponseReceivedDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (HttpVersion :> api) m = HttpVersion -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (BasicAuth realm usr :> api) m = usr -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Capture' mods capture a :> api) m = If (FoldLenient mods) (Either String a) a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (CaptureAll capture a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Description desc :> api) m = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Summary desc :> api) m = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (EmptyAPI :> api) m = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (AuthProtect tag :> api) m = AuthServerData (AuthProtect tag) -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Experimental.Auth · orphantype ServerT (Fragment a1 :> api) m = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Header' mods sym a :> api) m = RequestArgument mods a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (IsSecure :> api) m = IsSecure -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (NamedRoutes api) m = api (AsServerT m)Defined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (QueryFlag sym :> api) m = Bool -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (QueryParam' mods sym a :> api) m = RequestArgument mods a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (QueryParams sym a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (DeepQuery sym a :> api) m = a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (QueryString :> api) m = Query -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (RemoteHost :> api) m = SockAddr -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype 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.Internaltype ServerT (Stream method status framing ctype (Headers h a)) m = m (Headers h a)Defined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Stream method status framing ctype a) m = m aDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (StreamBody' mods framing ctype a :> api) m = a -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (UVerb method contentTypes as) m = m (Union as)Defined in servant-server-0.20.2 · Servant.Server.UVerb · orphantype ServerT (NoContentVerb method) m = m NoContentDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)Defined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Verb method status ctypes a) m = m aDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (WithNamedContext name subContext subApi) m = ServerT subApi mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (WithResource a :> api) m = (ReleaseKey, a) -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (Vault :> api) m = Vault -> ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (a :<|> b) m = ServerT a m :<|> ServerT b mDefined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (a -> b) m = TypeError (HasServerArrowTypeError a b)Defined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (arr :> sub) _1 = TypeError (PartialApplication HasServer arr)Defined in servant-server-0.20.2 · Servant.Server.Internaltype ServerT (path :> api) m = ServerT api mDefined in servant-server-0.20.2 · Servant.Server.Internal
type GServerConstraints (api :: Type -> Type) (m :: Type -> Type) = (ToServant api (AsServerT m) ~ ServerT (ToServantApi api) m, GServantProduct (Rep (api (AsServerT m))))Set of constraints required to convert to / from vanilla server types.
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)
Instances1GServer
(ToServant api (AsServerT m) ~ ServerT (ToServantApi api) m, GServantProduct (Rep (api (AsServerT m)))) => GServer api mDefined in servant-server-0.20.2 · Servant.Server.Internal