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).
:: a typeCtrl KGHC 9.14.1 · lts/ghc-9.14.x · 3e2d568 · 2026-10-11
Moduleservant-server-0.20.3.0Haskell2010
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).
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).
Get a Proxy of an API type.
See ToServant, but at value-level.
addHeader adds a header to a response. Note that it changes the type of
the value in the following ways:
A simple value is wrapped in "Headers '[hdr]":
let example0 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;getHeaders example0[("someheader","5")]
A value that already has a header has its new header *prepended* to the existing list:
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.
Look up a specific ResponseHeader, without having to know what position it is in the HList.
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
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:
:set -XTypeApplicationscase lookupResponseHeader @"1st" example2 of { Header b -> b ; _ -> False }True
Deliberately do not add a header to a value.
let example1 = noHeader "hi" :: Headers '[Header "someheader" Int] StringgetHeaders example1[]
safeLink Create a valid (by construction) relative URI with query params.
This function will only typecheck if endpoint is part of the API api
Parse value from HTTP API data.
WARNING: Do not derive this using DeriveAnyClass as the generated
instance will loop indefinitely.
parseUrlPiece :: Text -> Either Text aParse URL path piece.
parseHeader :: ByteString -> Either Text aParse HTTP header value.
parseQueryParam :: Text -> Either Text aParse query param value.
FromHttpApiData SetCookieDefined in http-api-data-0.7 · Web.Internal.HttpApiDataNote: this instance works correctly for alphanumeric name and value
parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookieRight (SetCookie {setCookieName = "SESSID", setCookieValue = "r2t5uvjq435r4q7ib3vtdjq120", setCookiePath = Nothing, setCookieExpires = Nothing, setCookieMaxAge = Nothing, setCookieDomain = Nothing, setCookieHttpOnly = False, setCookieSecure = False, setCookieSameSite = Nothing, setCookiePartitioned = False})
FromHttpApiData StringDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData VoidDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData IntegerDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData NaturalDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData AllDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData AnyDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData VersionDefined in http-api-data-0.7 · Web.Internal.HttpApiDatashowVersion <$> parseUrlPiece "1.2.3"Right "1.2.3"
FromHttpApiData Int16Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Int32Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Int64Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Int8Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData BoolDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData CharDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData DoubleDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData FloatDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData IntDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData OrderingDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData WordDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Word16Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Word32Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Word64Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData Word8Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData TextDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData TextDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData DayDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoGregorian <$> parseUrlPiece "2016-12-01"Right (2016,12,1)
FromHttpApiData MonthDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "2021-01" :: Either Text MonthRight 2021-01
FromHttpApiData QuarterDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "2021-q1" :: Either Text QuarterRight 2021-Q1
FromHttpApiData QuarterOfYearDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "q2" :: Either Text QuarterOfYearRight Q2
parseUrlPiece "Q3" :: Either Text QuarterOfYearRight Q3
FromHttpApiData DayOfWeekDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "Monday" :: Either Text DayOfWeekRight Monday
FromHttpApiData NominalDiffTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData UTCTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "2015-10-03T00:14:24Z" :: Either Text UTCTimeRight 2015-10-03 00:14:24 UTC
FromHttpApiData LocalTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "2015-10-03T14:55:01" :: Either Text LocalTimeRight 2015-10-03 14:55:01
FromHttpApiData TimeOfDayDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "14:55:01.333" :: Either Text TimeOfDayRight 14:55:01.333
FromHttpApiData ZonedTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "2015-10-03T14:55:01+0000" :: Either Text ZonedTimeRight 2015-10-03 14:55:01 +0000
parseQueryParam "2016-12-31T01:00:00Z" :: Either Text ZonedTimeRight 2016-12-31 01:00:00 +0000
FromHttpApiData UUIDDefined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData ()Defined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "_" :: Either Text ()Right ()
FromHttpApiData a => FromHttpApiData (First a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Last a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Max a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Min a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Identity a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (First a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Last a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Dual a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Product a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Sum a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Maybe a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "Just 123" :: Either Text (Maybe Int)Right (Just 123)
FromHttpApiData a => FromHttpApiData (LenientData a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataHasResolution a => FromHttpApiData (Fixed a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataNote: this instance is not polykinded
(KnownNat min, KnownNat max) => FromHttpApiData (Range min max)Defined in servant-0.20.3.0 · Servant.API.Range(FromHttpApiData a, FromHttpApiData b) => FromHttpApiData (Either a b)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataparseUrlPiece "Right 123" :: Either Text (Either String Int)Right (Right 123)
FromHttpApiData a => FromHttpApiData (Const a b)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataFromHttpApiData a => FromHttpApiData (Tagged b a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataNote: this instance is not polykinded
Convert value to HTTP API data.
WARNING: Do not derive this using DeriveAnyClass as the generated
instance will loop indefinitely.
toUrlPiece :: a -> TextConvert to URL path piece.
toEncodedUrlPiece :: a -> BuilderConvert to a URL path piece, making sure to encode any special chars.
The default definition uses urlEncodeBuilder False
but this may be overriden with a more efficient version.
toHeader :: a -> ByteStringConvert to HTTP header value.
toQueryParam :: a -> TextConvert to query param value.
toEncodedQueryParam :: a -> BuilderConvert to URL query param,
The default definition uses urlEncodeBuilder True
but this may be overriden with a more efficient version.
ToHttpApiData SetCookieDefined in http-api-data-0.7 · Web.Internal.HttpApiDataNote: this instance works correctly for alphanumeric name and value
let Right c = parseUrlPiece "SESSID=r2t5uvjq435r4q7ib3vtdjq120" :: Either Text SetCookietoUrlPiece c"SESSID=r2t5uvjq435r4q7ib3vtdjq120"
toHeader c"SESSID=r2t5uvjq435r4q7ib3vtdjq120"
ToHttpApiData StringDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData VoidDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData IntegerDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData NaturalDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData AllDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData AnyDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData VersionDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece (Version [1, 2, 3] [])"1.2.3"
ToHttpApiData Int16Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Int32Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Int64Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Int8Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData BoolDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData CharDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData DoubleDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData FloatDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData IntDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData OrderingDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData WordDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Word16Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Word32Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Word64Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData Word8Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData LinkDefined in servant-0.20.3.0 · Servant.LinksToHttpApiData TextDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData TextDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData DayDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece (fromGregorian 2015 10 03)"2015-10-03"
ToHttpApiData MonthDefined in http-api-data-0.7 · Web.Internal.HttpApiDataimport Data.Time.Calendar.Month.Compat (Month (..))MkMonth 244822040-03
toUrlPiece $ MkMonth 24482"2040-03"
ToHttpApiData QuarterDefined in http-api-data-0.7 · Web.Internal.HttpApiDataimport Data.Time.Calendar.Quarter.Compat (Quarter (..))MkQuarter 80402010-Q1
toUrlPiece $ MkQuarter 8040"2010-q1"
ToHttpApiData QuarterOfYearDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece Q4"q4"
ToHttpApiData DayOfWeekDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece Monday"monday"
ToHttpApiData NominalDiffTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData UTCTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece $ UTCTime (fromGregorian 2015 10 03) 864.5"2015-10-03T00:14:24.500Z"
ToHttpApiData LocalTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece $ LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 21.687)"2015-10-03T14:55:21.687"
ToHttpApiData TimeOfDayDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece $ TimeOfDay 14 55 23.1"14:55:23.100"
ToHttpApiData ZonedTimeDefined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece $ ZonedTime (LocalTime (fromGregorian 2015 10 03) (TimeOfDay 14 55 51.001)) utc"2015-10-03T14:55:51.001Z"
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.7 · Web.Internal.HttpApiDataToHttpApiData ()Defined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece ()"_"
ToHttpApiData a => ToHttpApiData (First a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Last a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Max a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Min a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Identity a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (First a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Last a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Dual a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Product a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Sum a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Maybe a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece (Just "Hello")"just Hello"
HasResolution a => ToHttpApiData (Fixed a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataNote: this instance is not polykinded
ToHttpApiData (Range min max)Defined in servant-0.20.3.0 · Servant.API.Range(ToHttpApiData a, ToHttpApiData b) => ToHttpApiData (Either a b)Defined in http-api-data-0.7 · Web.Internal.HttpApiDatatoUrlPiece (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.7 · Web.Internal.HttpApiDataToHttpApiData a => ToHttpApiData (Tagged b a)Defined in http-api-data-0.7 · Web.Internal.HttpApiDataNote: this instance is not polykinded
HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).
Bounded StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodEnum StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodEq StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodData StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodOrd StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodRead StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodShow StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodIx StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodGeneric StdMethodDefined in http-types-0.12.6 · Network.HTTP.Types.MethodReflectMethod 'CONNECTDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'DELETEDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'GETDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'HEADDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'OPTIONSDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'PATCHDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'POSTDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'PUTDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'TRACEDefined in servant-0.20.3.0 · Servant.API.Verbstype Rep StdMethod = D1 ('MetaData "StdMethod"
"Network.HTTP.Types.Method"
"http-types-0.12.6-JXdWbZY7LRKJLPFys5QcBS"
'False) (((C1 ('MetaCons "GET"
'PrefixI 'False) U1 :+: C1 ('MetaCons "POST"
'PrefixI 'False) U1) :+: (C1 ('MetaCons "HEAD"
'PrefixI 'False) U1 :+: C1 ('MetaCons "PUT"
'PrefixI 'False) U1)) :+: ((C1 ('MetaCons "DELETE"
'PrefixI 'False) U1 :+: C1 ('MetaCons "TRACE"
'PrefixI 'False) U1) :+: (C1 ('MetaCons "CONNECT"
'PrefixI 'False) U1 :+: (C1 ('MetaCons "OPTIONS"
'PrefixI 'False) U1 :+: C1 ('MetaCons "PATCH"
'PrefixI 'False) U1))))Defined in http-types-0.12.6 · Network.HTTP.Types.MethodHTTP Version.
Note that the Show instance is intended merely for debugging.
Eq HttpVersionDefined in http-types-0.12.6 · Network.HTTP.Types.VersionData HttpVersionDefined in http-types-0.12.6 · Network.HTTP.Types.VersionOrd HttpVersionDefined in http-types-0.12.6 · Network.HTTP.Types.VersionShow HttpVersionDefined in http-types-0.12.6 · Network.HTTP.Types.Versionshow http11"HTTP/1.1"
Generic HttpVersionDefined in http-types-0.12.6 · Network.HTTP.Types.VersionHasLink sub => HasLink (HttpVersion :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasServer api context => HasServer (HttpVersion :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype Rep HttpVersion = D1 ('MetaData "HttpVersion"
"Network.HTTP.Types.Version"
"http-types-0.12.6-JXdWbZY7LRKJLPFys5QcBS"
'False) (C1 ('MetaCons "HttpVersion"
'PrefixI 'True) (S1 ('MetaSel ('Just "httpMajor"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Int) :*: S1 ('MetaSel ('Just "httpMinor"
) 'NoSourceUnpackedness 'SourceStrict 'DecidedUnpack) (Rec0 Int)))Defined in http-types-0.12.6 · Network.HTTP.Types.Versiontype MkLink (HttpVersion :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (HttpVersion :> api) m = HttpVersion -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalRepresents a general universal resource identifier using its component parts.
For example, for the URI
foo://anonymous@www.haskell.org:42/ghc?query#fragthe components are:
Eq URIDefined in network-uri-2.6.4.2 · Network.URIData URIDefined in network-uri-2.6.4.2 · Network.URIOrd URIDefined in network-uri-2.6.4.2 · Network.URIShow URIDefined in network-uri-2.6.4.2 · Network.URIGeneric URIDefined in network-uri-2.6.4.2 · Network.URINFData URIDefined in network-uri-2.6.4.2 · Network.URIFromJSON URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSONFromJSONKey URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSONToJSON URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.ToJSONToJSONKey URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.ToJSONLift URIDefined in network-uri-2.6.4.2 · Network.URItype Rep URI = D1 ('MetaData "URI"
"Network.URI"
"network-uri-2.6.4.2-1QdlAcNSbcxeQT6IyDD14"
'False) (C1 ('MetaCons "URI"
'PrefixI 'True) ((S1 ('MetaSel ('Just "uriScheme"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "uriAuthority"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe URIAuth))) :*: (S1 ('MetaSel ('Just "uriPath"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Just "uriQuery"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "uriFragment"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))))Defined in network-uri-2.6.4.2 · Network.URIUnion of two APIs, first takes precedence in case of overlap.
Example:
:{type MyApi = "books" :> Get '[JSON] [Book] -- GET /books :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] () -- POST /books:}
a :<|> binfixr 3Bifoldable (:<|>)Defined in servant-0.20.3.0 · Servant.API.AlternativeBifunctor (:<|>)Defined in servant-0.20.3.0 · Servant.API.AlternativeBitraversable (:<|>)Defined in servant-0.20.3.0 · Servant.API.AlternativeBiapplicative (:<|>)Defined in servant-0.20.3.0 · Servant.API.Alternative(HasLink a, HasLink b) => HasLink (a :<|> b)Defined in servant-0.20.3.0 · Servant.Links(HasServer a context, HasServer b context) => HasServer (a :<|> b) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalA 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.3.0 · Servant.API.AlternativeFoldable ((:<|>) a)Defined in servant-0.20.3.0 · Servant.API.AlternativeTraversable ((:<|>) a)Defined in servant-0.20.3.0 · Servant.API.Alternative(Bounded a, Bounded b) => Bounded (a :<|> b)Defined in servant-0.20.3.0 · Servant.API.Alternative(Eq a, Eq b) => Eq (a :<|> b)Defined in servant-0.20.3.0 · Servant.API.Alternative(Show a, Show b) => Show (a :<|> b)Defined in servant-0.20.3.0 · Servant.API.Alternative(Semigroup a, Semigroup b) => Semigroup (a :<|> b)Defined in servant-0.20.3.0 · Servant.API.Alternative(Monoid a, Monoid b) => Monoid (a :<|> b)Defined in servant-0.20.3.0 · Servant.API.Alternativetype MkLink (a :<|> b) r = MkLink a r :<|> MkLink b rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (a :<|> b) m = ServerT a m :<|> ServerT b mDefined in servant-server-0.20.3.0 · Servant.Server.InternalCombinator 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.
HasLink sub => HasLink (BasicAuth realm a :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalBasic Authentication
type MkLink (BasicAuth realm a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (BasicAuth realm usr :> api) m = usr -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalA simple datatype to hold data required to decorate a request
Capture a value from the request path under a certain type a.
Example:
-- GET /books/:isbntype MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
Capture which can be modified. For example with Description.
(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(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.3.0 · Servant.Server.InternalIf 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 = ...type MkLink (Capture' mods sym v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Capture' mods capture a :> api) m = If (FoldLenient mods) (Either String a) a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalCapture all remaining values from the request path under a certain type
a.
Example:
-- GET /src/*type MyAPI = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub)Defined in servant-0.20.3.0 · 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.3.0 · 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 = ...type MkLink (CaptureAll sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (CaptureAll capture a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalInstances 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:
import Network.HTTP.Media ((//), (/:))data HTML:{instance Accept HTML where contentType _ = "text" // "html" /: ("charset", "utf-8"):}
contentType :: Proxy ctype -> MediaTypecontentTypes :: Proxy ctype -> NonEmpty MediaTypeAccept EventStreamDefined in servant-0.20.3.0 · Servant.API.ContentTypestext/event-streamAccept FormUrlEncodedDefined in servant-0.20.3.0 · Servant.API.ContentTypesapplication/x-www-form-urlencodedAccept JSONDefined in servant-0.20.3.0 · Servant.API.ContentTypesapplication/jsonAccept OctetStreamDefined in servant-0.20.3.0 · Servant.API.ContentTypesapplication/octet-streamAccept PlainTextDefined in servant-0.20.3.0 · Servant.API.ContentTypestext/plain;charset=utf-8Accept FormUrlEncodedDefined in servant-0.20.3.0 · Servant.API.ContentTypesapplication/x-www-form-urlencodedToForm a => MimeRender FormUrlEncoded aDefined in servant-0.20.3.0 · Servant.API.ContentTypesurlEncodeAsForm
Note that the mimeUnrender p (mimeRender p x) == Right x law only
holds if every element of x is non-null (i.e., not ("", ""))
FromForm a => MimeUnrender FormUrlEncoded aDefined in servant-0.20.3.0 · Servant.API.ContentTypesurlDecodeAsForm
Note that the mimeUnrender p (mimeRender p x) == Right x law only
holds if every element of x is non-null (i.e., not ("", ""))
MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbAccept JSONDefined in servant-0.20.3.0 · Servant.API.ContentTypesapplication/jsonToJSON a => MimeRender JSON aDefined in servant-0.20.3.0 · Servant.API.ContentTypesFromJSON a => MimeUnrender JSON aDefined in servant-0.20.3.0 · Servant.API.ContentTypesMimeRender JSON a => MimeRender JSON (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbInstantiate 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] IntmimeRender :: Proxy ctype -> a -> ByteStringToJSON a => MimeRender JSON aDefined in servant-0.20.3.0 · Servant.API.ContentTypesToForm a => MimeRender FormUrlEncoded aDefined in servant-0.20.3.0 · Servant.API.ContentTypesurlEncodeAsForm
Note that the mimeUnrender p (mimeRender p x) == Right x law only
holds if every element of x is non-null (i.e., not ("", ""))
MimeRender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesMimeRender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesidMimeRender PlainText StringDefined in servant-0.20.3.0 · Servant.API.ContentTypesBC.packMimeRender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesfromStrict . TextS.encodeUtf8MimeRender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesMimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeRender JSON a => MimeRender JSON (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeRender PlainText a => MimeRender PlainText (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbInstantiate this class to register a way of deserializing a type based
on the request's Content-Type header.
import Network.HTTP.Media hiding (Accept)import qualified Data.ByteString.Lazy.Char8 as BSCdata MyContentType = MyContentType String
:{instance Accept MyContentType where contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8"):}
:{instance Read a => MimeUnrender MyContentType a where mimeUnrender _ bs = case BSC.take 12 bs of "MyContentType" -> return . read . BSC.unpack $ BSC.drop 12 bs _ -> Left "didn't start with the magic incantation":}
type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] IntmimeUnrender :: Proxy ctype -> ByteString -> Either String amimeUnrenderWithType :: Proxy ctype -> MediaType -> ByteString -> Either String aFromJSON a => MimeUnrender JSON aDefined in servant-0.20.3.0 · Servant.API.ContentTypesFromForm a => MimeUnrender FormUrlEncoded aDefined in servant-0.20.3.0 · Servant.API.ContentTypesurlDecodeAsForm
Note that the mimeUnrender p (mimeRender p x) == Right x law only
holds if every element of x is non-null (i.e., not ("", ""))
MimeUnrender EventStream EventStreamChunkDefined in servant-0.20.3.0 · Servant.API.ContentTypesMimeUnrender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesRight . toStrictMimeUnrender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesRight . idMimeUnrender PlainText StringDefined in servant-0.20.3.0 · Servant.API.ContentTypesRight . BC.unpackMimeUnrender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesleft show . TextS.decodeUtf8' . toStrictMimeUnrender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesleft show . TextL.decodeUtf8'MimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbA type for responses without content-body.
Eq NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypesRead NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypesShow NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypesGeneric NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypesNFData NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypesHasStatus NoContentDefined in servant-0.20.3.0 · Servant.API.UVerbIf 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.
Accept ctyp => AllMimeRender '[ctyp] NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypesAllMime (ctyp ': ctyp' ': ctyps) => AllMimeRender (ctyp ': ctyp' ': ctyps) NoContentDefined in servant-0.20.3.0 · Servant.API.ContentTypestype Rep NoContent = D1 ('MetaData "NoContent"
"Servant.API.ContentTypes"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) (C1 ('MetaCons "NoContent"
'PrefixI 'False) U1)Defined in servant-0.20.3.0 · Servant.API.ContentTypestype StatusOf NoContent = 204
Defined in servant-0.20.3.0 · Servant.API.UVerbAccept OctetStreamDefined in servant-0.20.3.0 · Servant.API.ContentTypesapplication/octet-streamMimeRender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesMimeRender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesidMimeUnrender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesRight . toStrictMimeUnrender OctetStream ByteStringDefined in servant-0.20.3.0 · Servant.API.ContentTypesRight . idMimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbAccept PlainTextDefined in servant-0.20.3.0 · Servant.API.ContentTypestext/plain;charset=utf-8MimeRender PlainText StringDefined in servant-0.20.3.0 · Servant.API.ContentTypesBC.packMimeRender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesfromStrict . TextS.encodeUtf8MimeRender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesMimeUnrender PlainText StringDefined in servant-0.20.3.0 · Servant.API.ContentTypesRight . BC.unpackMimeUnrender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesleft show . TextS.decodeUtf8' . toStrictMimeUnrender PlainText TextDefined in servant-0.20.3.0 · Servant.API.ContentTypesleft show . TextL.decodeUtf8'MimeRender PlainText a => MimeRender PlainText (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbAdd more verbose description for (part of) API.
Example:
:{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:}
HasLink sub => HasLink (Description s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasServer api ctx => HasServer (Description desc :> api) ctxDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore Description in server handlers.
type MkLink (Description s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Description desc :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalAdd a short summary for (part of) API.
Example:
type MyApi = Summary "Get book by ISBN." :> "books" :> Capture "isbn" Text :> Get '[JSON] BookHasLink sub => HasLink (Summary s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasServer api ctx => HasServer (Summary desc :> api) ctxDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore Summary in server handlers.
type MkLink (Summary s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Summary desc :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalAn 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.
Bounded EmptyAPIDefined in servant-0.20.3.0 · Servant.API.EmptyEnum EmptyAPIDefined in servant-0.20.3.0 · Servant.API.EmptyEq EmptyAPIDefined in servant-0.20.3.0 · Servant.API.EmptyShow EmptyAPIDefined in servant-0.20.3.0 · Servant.API.EmptyHasLink EmptyAPIDefined in servant-0.20.3.0 · Servant.LinksHasServer EmptyAPI contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalThe server for an EmptyAPI is emptyServer.
type MyApi = "nothing" :> EmptyApi
server :: Server MyApi
server = emptyServerHasServer api context => HasServer (EmptyAPI :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore EmptyAPI as part of route in server handlers.
type MkLink EmptyAPI a = EmptyAPIDefined in servant-0.20.3.0 · Servant.Linkstype ServerT EmptyAPI m = Tagged m EmptyServerDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (EmptyAPI :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalA generalized Authentication combinator. Use this if you have a non-standard authentication technique.
NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE.
HasLink sub => HasLink (AuthProtect tag :> sub)Defined in servant-0.20.3.0 · Servant.Links(HasServer api context, HasContextEntry context (AuthHandler Request (AuthServerData (AuthProtect tag)))) => HasServer (AuthProtect tag :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Experimental.Auth · orphanKnown orphan instance.
type MkLink (AuthProtect tag :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (AuthProtect tag :> api) m = AuthServerData (AuthProtect tag) -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Experimental.Auth · orphanDocument the URI fragment in API. Useful in combination with Link.
Example:
-- /post#TRACKINGtype MyApi = "post" :> Fragment Text :> Get '[JSON] Tracking
(HasLink sub, ToHttpApiData v) => HasLink (Fragment v :> sub)Defined in servant-0.20.3.0 · Servant.Links(AtMostOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer api context) => HasServer (Fragment a1 :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore 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...AtMostOneFragment (Fragment a)Defined in servant-0.20.3.0 · Servant.API.TypeLeveltype MkLink (Fragment v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Fragment a1 :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalA type that specifies that an API record contains an API definition. Only useful at type-level.
GenericMode AsApiDefined in servant-0.20.3.0 · Servant.API.Generictype (:-) AsApi api = apiDefined in servant-0.20.3.0 · Servant.API.GenericGServantProduct (K1 i c)Defined in servant-0.20.3.0 · Servant.API.Generic(GServantProduct l, GServantProduct r) => GServantProduct (l :*: r)Defined in servant-0.20.3.0 · Servant.API.GenericGServantProduct f => GServantProduct (M1 i c f)Defined in servant-0.20.3.0 · Servant.API.GenericA class with a type family that applies an appropriate type family to the api
parameter. For example, AsApi will leave api untouched, while
will produce AsServerT m.ServerT api m
type family (:-) (mode :: k) apiGenericMode AsApiDefined in servant-0.20.3.0 · Servant.API.GenericGenericMode (AsLink a)Defined in servant-0.20.3.0 · Servant.LinksGenericMode (AsServerT m)Defined in servant-server-0.20.3.0 · Servant.Server.Internaltype GenericServant (routes :: k -> Type) (mode :: k) = (GenericMode mode, Generic (routes mode), GServantProduct (Rep (routes mode)))A constraint alias, for work with mode and routes.
Turns a generic product type into a tree of :<|> combinators.
Extract the given header's value as a value of type a.
I.e. header sent by client, parsed by server.
Example:
newtype Referer = Referer Text deriving (Eq, Show) -- GET /view-my-referertype MyApi = "view-my-referer" :> Header "from" Referer :> Get '[JSON] Referer
(KnownSymbol h, ToHttpApiData v) => AddHeader mods h v (Headers (fst ': rest) a) (Headers (Header' mods h v ': fst ': rest) a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersHasResponseHeader h a (Header' mods h a ': rest)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersHasLink sub => HasLink (Header' mods sym a :> sub)Defined in servant-0.20.3.0 · Servant.Links(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.3.0 · Servant.Server.InternalIf 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(KnownSymbol name, ToHttpApiData x) => ServantHeader (Header' mods name x) name xDefined in servant-0.20.3.0 · Servant.API.MultiVerb(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header' mods h v ': xs)Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header' mods h v ': rest)Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(KnownSymbol h, ToHttpApiData x, GetHeadersFromHList xs) => GetHeadersFromHList (Header' mods h x ': xs)Defined in servant-0.20.3.0 · Servant.API.ResponseHeaderstype MkLink (Header' mods sym a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Header' mods sym a :> api) m = RequestArgument mods a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalMatch against the given host.
This allows you to define APIs over multiple domains. For example:
type API = Host "api1.example" :> API1
:<|> Host "api2.example" :> API2(KnownSymbol sym, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Host sym :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Host sym :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalWas 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.
Eq IsSecureDefined in servant-0.20.3.0 · Servant.API.IsSecureOrd IsSecureDefined in servant-0.20.3.0 · Servant.API.IsSecureRead IsSecureDefined in servant-0.20.3.0 · Servant.API.IsSecureShow IsSecureDefined in servant-0.20.3.0 · Servant.API.IsSecureGeneric IsSecureDefined in servant-0.20.3.0 · Servant.API.IsSecureHasLink sub => HasLink (IsSecure :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasServer api context => HasServer (IsSecure :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype Rep IsSecure = D1 ('MetaData "IsSecure"
"Servant.API.IsSecure"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) (C1 ('MetaCons "Secure"
'PrefixI 'False) U1 :+: C1 ('MetaCons "NotSecure"
'PrefixI 'False) U1)Defined in servant-0.20.3.0 · Servant.API.IsSecuretype MkLink (IsSecure :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (IsSecure :> api) m = IsSecure -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalOptional argument. Wrapped in Maybe.
Required argument. Not wrapped.
Strictly parsed argument. Not wrapped.
Combinator for embedding a record of named routes into a Servant API type.
(HasLink (ToServantApi routes), forall a. GLink routes a, ErrorIfNoGeneric routes) => HasLink (NamedRoutes routes)Defined in servant-0.20.3.0 · Servant.Links(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.3.0 · Servant.Server.Internaltype MkLink (NamedRoutes routes) a = routes (AsLink a)Defined in servant-0.20.3.0 · Servant.Linkstype ServerT (NamedRoutes api) m = api (AsServerT m)Defined in servant-server-0.20.3.0 · Servant.Server.InternalLookup a potentially value-less query string parameter
with boolean semantics. If the param sym is there without any value,
or if it's there with value "true" or "1", it's interpreted as True.
Otherwise, it's interpreted as False.
Example:
-- /books?publishedtype MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book]
(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api) contextDefined in servant-server-0.20.3.0 · 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...type MkLink (QueryFlag sym :> sub) a = Bool -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (QueryFlag sym :> api) m = Bool -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalLookup the value associated to the sym query string parameter
and try to extract it as a value of type a.
Example:
-- /books?author=<author name>type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]
QueryParam which can be Required, Lenient, or modified otherwise.
(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(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.3.0 · 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 type QueryParam "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...type MkLink (QueryParam' mods sym v :> sub) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (QueryParam' mods sym a :> api) m = RequestArgument mods a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalLookup the values associated to the sym query string parameter
and try to extract it as a value of type [a]. This is typically
meant to support query string parameters of the form
param[]=val1¶m[]=val2 and so on. Note that servant doesn't actually
require the []s and will fetch the values just fine with
param=val1¶m=val2, too.
Example:
-- /books?authors[]=<author1>&authors[]=<author2>&...type MyApi = "books" :> QueryParams "authors" Text :> Get '[JSON] [Book]
(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, FromHttpApiData a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (QueryParams sym a :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIf 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.3.0 · Servant.Linkstype ServerT (QueryParams sym a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalExtract an deep object from a query string.
Example:
-- /books?filter[author][name]=<author name>&filter[year]=<book year>type MyApi = "books" :> DeepQuery "filter" BookQuery :> Get '[JSON] [Book]
(KnownSymbol sym, ToDeepQuery record, HasLink sub) => HasLink (DeepQuery sym record :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, FromDeepQuery a, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (DeepQuery sym a :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIf 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 (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 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 MkLink (DeepQuery sym record :> sub) a = record -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (DeepQuery sym a :> api) m = a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalExtract 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:
-- /books?author=<author name>&year=<book year>type MyApi = "books" :> QueryString :> Get '[JSON] [Book]
HasServer api context => HasServer (QueryString :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIf 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.3.0 · Servant.Server.InternalEndpoint 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
HasLink RawDefined in servant-0.20.3.0 · Servant.LinksHasServer Raw contextDefined in servant-server-0.20.3.0 · 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"type MkLink Raw a = aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT Raw m = Tagged m ApplicationDefined in servant-server-0.20.3.0 · Servant.Server.InternalVariant of Raw that lets you access the underlying monadic context to process the request.
HasLink RawMDefined in servant-0.20.3.0 · Servant.LinksHasServer RawM contextDefined in servant-server-0.20.3.0 · 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"type MkLink RawM a = aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT RawM m = Request -> (Response -> IO ResponseReceived) -> m ResponseReceivedDefined in servant-server-0.20.3.0 · Servant.Server.InternalProvides access to the host or IP address from which the HTTP request was sent.
HasLink sub => HasLink (RemoteHost :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasServer api context => HasServer (RemoteHost :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype MkLink (RemoteHost :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (RemoteHost :> api) m = SockAddr -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalExtract the request body as a value of type a.
Example:
-- POST /bookstype MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
HasLink sub => HasLink (ReqBody' mods ct a :> sub)Defined in servant-0.20.3.0 · 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.3.0 · Servant.Server.InternalIf 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.3.0 · Servant.Linkstype ServerT (ReqBody' mods list a :> api) m = If (FoldLenient mods) (Either String a) a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internalclass AddHeader (mods :: [Type]) (h :: Symbol) v orig new | mods h v orig -> new, new -> mods, new -> h, new -> v, new -> orig where(KnownSymbol h, ToHttpApiData v, new ~ Headers '[Header' mods h v] a) => AddHeader mods h v a newDefined in servant-0.20.3.0 · Servant.API.ResponseHeadersAddHeader mods h v old new => AddHeader mods h v (Union '[old]) (Union '[new])Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(AddHeader mods h v old new, AddHeader mods h v (Union oldrest) (Union newrest), oldrest ~ (a ': as), newrest ~ (b ': bs)) => AddHeader mods h v (Union (old ': a ': as)) (Union (new ': b ': bs))Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(KnownSymbol h, ToHttpApiData v) => AddHeader mods h v (Headers (fst ': rest) a) (Headers (Header' mods h v ': fst ': rest) a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersbuildHeadersTo :: [Header] -> HList hsBuildHeadersTo '[]Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header' mods h v ': xs)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersgetHeaders :: ls -> [Header]GetHeadersFromHList hs => GetHeaders (HList hs)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersGetHeaders' hs => GetHeaders (Headers hs a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersNFDataHList xs => NFData (HList xs)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersGetHeadersFromHList hs => GetHeaders (HList hs)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersHasResponseHeader h a (Header' mods h a ': rest)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersHasResponseHeader h a rest => HasResponseHeader h a (first ': rest)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersResponse Header objects. You should never need to construct one directly.
Instead, use addOptionalHeader.
HeadersgetResponse :: aThe underlying value of a Headers
getHeadersHList :: HList lsHList of headers.
(KnownSymbol h, ToHttpApiData v) => AddHeader mods h v (Headers (fst ': rest) a) (Headers (Header' mods h v ': fst ': rest) a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(IsServerResource cts a, GetHeaders (Headers h a)) => IsServerResource cts (Headers h a)Defined in servant-server-0.20.3.0 · Servant.Server.UVerb(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.3.0 · 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.3.0 · Servant.Server.InternalFunctor (Headers ls)Defined in servant-0.20.3.0 · Servant.API.ResponseHeaders(NFDataHList ls, NFData a) => NFData (Headers ls a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersGetHeaders' hs => GetHeaders (Headers hs a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersHasStatus a => HasStatus (Headers ls a)Defined in servant-0.20.3.0 · Servant.API.UVerbtype StatusOf (Headers ls a) = StatusOf aDefined in servant-0.20.3.0 · Servant.API.UVerbtype ServerT (Stream method status framing ctype (Headers h a)) m = m (Headers h a)Defined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)Defined in servant-server-0.20.3.0 · Servant.Server.InternalFunctor (ResponseHeader sym)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersEq a => Eq (ResponseHeader sym a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersShow a => Show (ResponseHeader sym a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersNFData a => NFData (ResponseHeader sym a)Defined in servant-0.20.3.0 · Servant.API.ResponseHeadersServer-sent events (SSE)
Generic (ServerSentEvents' method status kind a)Defined in servant-0.20.3.0 · Servant.API.ServerSentEventstype Rep (ServerSentEvents' method status kind a) = D1 ('MetaData "ServerSentEvents'"
"Servant.API.ServerSentEvents"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) V1Defined in servant-0.20.3.0 · Servant.API.ServerSentEventsThe 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.
framingRender :: Monad m => Proxy strategy -> (a -> ByteString) -> SourceT m a -> SourceT m ByteStringFramingRender NetstringFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingRender NewlineFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingRender NoFramingDefined in servant-0.20.3.0 · Servant.API.StreamThe FramingUnrender class provides the logic for parsing a framing strategy.
framingUnrender :: Monad m => Proxy strategy -> (ByteString -> Either String a) -> SourceT m ByteString -> SourceT m aFramingUnrender NetstringFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingUnrender NewlineFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingUnrender NoFramingDefined in servant-0.20.3.0 · Servant.API.StreamAs 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.
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.
fromSourceIO :: SourceIO chunk -> IO aMonadIO m => FromSourceIO a (SourceT m a)Defined in servant-0.20.3.0 · Servant.API.StreamThe 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:,".
FramingRender NetstringFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingUnrender NetstringFramingDefined in servant-0.20.3.0 · Servant.API.StreamA 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).
FramingRender NewlineFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingUnrender NewlineFramingDefined in servant-0.20.3.0 · Servant.API.StreamA 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
FramingRender NoFramingDefined in servant-0.20.3.0 · Servant.API.StreamFramingUnrender NoFramingDefined in servant-0.20.3.0 · Servant.API.StreamAs 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.
IsWaiBody (SourceIO ByteString)Defined in servant-server-0.20.3.0 · Servant.Server.Internal.ResponseRenderA 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.
HasLink (Stream m status fr ct a)Defined in servant-0.20.3.0 · Servant.Links(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.3.0 · 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.3.0 · Servant.Server.InternalGeneric (Stream method status framing contentType a)Defined in servant-0.20.3.0 · Servant.API.Streamtype Rep (Stream method status framing contentType a) = D1 ('MetaData "Stream"
"Servant.API.Stream"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) V1Defined in servant-0.20.3.0 · Servant.API.Streamtype MkLink (Stream m status fr ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Stream method status framing ctype (Headers h a)) m = m (Headers h a)Defined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Stream method status framing ctype a) m = m aDefined in servant-server-0.20.3.0 · Servant.Server.InternalA stream request body.
HasLink sub => HasLink (StreamBody' mods framing ct a :> sub)Defined in servant-0.20.3.0 · Servant.Links(FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk, HasServer api context) => HasServer (StreamBody' mods framing ctype a :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalGeneric (StreamBody' mods framing contentType a)Defined in servant-0.20.3.0 · Servant.API.Streamtype Rep (StreamBody' mods framing contentType a) = D1 ('MetaData "StreamBody'"
"Servant.API.Stream"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) V1Defined in servant-0.20.3.0 · Servant.API.Streamtype MkLink (StreamBody' mods framing ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (StreamBody' mods framing ctype a :> api) m = a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalToSourceIO 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.
toSourceIO :: a -> SourceIO chunkToSourceIO a (NonEmpty a)Defined in servant-0.20.3.0 · Servant.API.StreamToSourceIO a [a]Defined in servant-0.20.3.0 · Servant.API.StreamSourceToSourceIO m => ToSourceIO chunk (SourceT m chunk)Defined in servant-0.20.3.0 · Servant.API.StreamRelax to use auxiliary class, have m
The contained API (second argument) can be found under ("/" ++ path)
(path being the first argument).
Example:
-- GET /hello/world-- returning a JSON encoded World valuetype MyApi = "hello" :> "world" :> Get '[JSON] World
TypeError (NoInstanceForSub HasLink ty) => HasLink (ty :> sub)Defined in servant-0.20.3.0 · Servant.LinksTypeError (PartialApplication HasLink arr) => HasLink (arr :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (HttpVersion :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (BasicAuth realm a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Description s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Summary s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (AuthProtect tag :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Header' mods sym a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (IsSecure :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (RemoteHost :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (ReqBody' mods ct a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (StreamBody' mods framing ct a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (WithResource res :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Vault :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToDeepQuery record, HasLink sub) => HasLink (DeepQuery sym record :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasLink sub) => HasLink (sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(HasLink sub, ToHttpApiData v) => HasLink (Fragment v :> sub)Defined in servant-0.20.3.0 · Servant.LinksTypeError (NoInstanceForSub HasServer ty) => HasServer (ty :> sub) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalTypeError (PartialApplication HasServer arr) => HasServer (arr :> sub) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalHasServer api context => HasServer (HttpVersion :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalHasServer api context => HasServer (EmptyAPI :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore EmptyAPI as part of route in server handlers.
HasServer api context => HasServer (IsSecure :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalHasServer api context => HasServer (QueryString :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIf 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...HasServer api context => HasServer (RemoteHost :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalHasServer api context => HasServer (Vault :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalHasServer api ctx => HasServer (Description desc :> api) ctxDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore Description in server handlers.
HasServer api ctx => HasServer (Summary desc :> api) ctxDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore Summary in 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.3.0 · 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.3.0 · Servant.Server.InternalIf 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 = ...(KnownSymbol path, HasServer api context) => HasServer (path :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalMake sure the incoming request starts with "/path", strip it and
pass the rest of the request path to api.
(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api) contextDefined in servant-server-0.20.3.0 · 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.3.0 · Servant.Server.InternalIf 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...(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.3.0 · Servant.Server.InternalIf 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(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.3.0 · 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 type QueryParam "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.3.0 · Servant.Server.InternalIf 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 (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 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...(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api) contextDefined in servant-server-0.20.3.0 · 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...(KnownSymbol sym, HasServer api context, HasContextEntry (MkContextWithErrorFormatter context) ErrorFormatters) => HasServer (Host sym :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internal(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.3.0 · Servant.Server.InternalIf 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...(FramingUnrender framing, FromSourceIO chunk a, MimeUnrender ctype chunk, HasServer api context) => HasServer (StreamBody' mods framing ctype a :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internal(AtMostOneFragment api, FragmentUnique (Fragment a1 :> api), HasServer api context) => HasServer (Fragment a1 :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalIgnore 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...(HasServer api context, HasContextEntry context (AuthHandler Request (AuthServerData (AuthProtect tag)))) => HasServer (AuthProtect tag :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Experimental.Auth · orphanKnown orphan instance.
(HasServer api ctx, HasContextEntry ctx (Acquire a)) => HasServer (WithResource a :> api) ctxDefined in servant-server-0.20.3.0 · 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.
type MkLink (HttpVersion :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (BasicAuth realm a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Capture' mods sym v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (CaptureAll sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Description s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Summary s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (AuthProtect tag :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Fragment v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Header' mods sym a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (IsSecure :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryFlag sym :> sub) a = Bool -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryParam' mods sym v :> sub) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryParams sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (DeepQuery sym record :> sub) a = record -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (RemoteHost :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (ReqBody' mods ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (StreamBody' mods framing ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (WithResource res :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Vault :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (arr :> sub) _1 = TypeError (PartialApplication HasLink arr)Defined in servant-0.20.3.0 · Servant.Linkstype MkLink (sym :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (HttpVersion :> api) m = HttpVersion -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (BasicAuth realm usr :> api) m = usr -> ServerT api mDefined in servant-server-0.20.3.0 · 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.3.0 · Servant.Server.Internaltype ServerT (CaptureAll capture a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Description desc :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Summary desc :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (EmptyAPI :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (AuthProtect tag :> api) m = AuthServerData (AuthProtect tag) -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Experimental.Auth · orphantype ServerT (Fragment a1 :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Header' mods sym a :> api) m = RequestArgument mods a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Host sym :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (IsSecure :> api) m = IsSecure -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (QueryFlag sym :> api) m = Bool -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (QueryParam' mods sym a :> api) m = RequestArgument mods a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (QueryParams sym a :> api) m = [a] -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (DeepQuery sym a :> api) m = a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (QueryString :> api) m = Query -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (RemoteHost :> api) m = SockAddr -> ServerT api mDefined in servant-server-0.20.3.0 · 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.3.0 · Servant.Server.Internaltype ServerT (StreamBody' mods framing ctype a :> api) m = a -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (WithResource a :> api) m = (ReleaseKey, a) -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Vault :> api) m = Vault -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (arr :> sub) _1 = TypeError (PartialApplication HasServer arr)Defined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (path :> api) m = ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalClosed type family, check if endpoint is within api.
Uses IsElem' if it exhausts all other options.
ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))OK
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:
ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))OK
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).
IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)IsElem (e :> sa) (e :> sb) = IsElem sa sbIsElem sa (Header sym x :> sb) = IsElem sa sbIsElem sa (Header' mods sym x :> sb) = IsElem sa sbIsElem sa (ReqBody y x :> sb) = IsElem sa sbIsElem (CaptureAll z y :> sa) (CaptureAll x y :> sb) = IsElem sa sbIsElem (Capture z y :> sa) (Capture x y :> sb) = IsElem sa sbIsElem sa (QueryParam x y :> sb) = IsElem sa sbIsElem sa (QueryParams x y :> sb) = IsElem sa sbIsElem sa (QueryFlag x :> sb) = IsElem sa sbIsElem sa (Fragment x :> sb) = IsElem sa sbIsElem (Verb m s ct typ) (Verb m s ct' typ) = IsSubList ct ct'IsElem e e = ()IsElem e (NamedRoutes rs) = IsElem e (ToServantApi rs)IsElem e a = IsElem' e aYou may use this type family to tell the type checker that your custom
type may be skipped as part of a link. This is useful for things like
QueryParam that are optional in a URI and do not affect them if they are
omitted.
data 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.
HasStatus NoContentDefined in servant-0.20.3.0 · Servant.API.UVerbIf 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.3.0 · Servant.API.UVerban 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.3.0 · Servant.API.UVerbA 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.
HasLink (UVerb m ct a)Defined in servant-0.20.3.0 · Servant.Links(ReflectMethod method, AllMime contentTypes, All (IsServerResourceWithStatus contentTypes) as, Unique (Statuses as)) => HasServer (UVerb method contentTypes as) contextDefined in servant-server-0.20.3.0 · Servant.Server.UVerb · orphanAtMostOneFragment (UVerb m cts as)Defined in servant-0.20.3.0 · Servant.API.TypeLeveltype MkLink (UVerb m ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (UVerb method contentTypes as) m = m (Union as)Defined in servant-server-0.20.3.0 · Servant.Server.UVerb · orphanA simple newtype wrapper that pairs a type with its status code. It implements all the content types that Servant ships with by default.
MimeRender FormUrlEncoded a => MimeRender FormUrlEncoded (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeRender JSON a => MimeRender JSON (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeRender OctetStream a => MimeRender OctetStream (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeRender PlainText a => MimeRender PlainText (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender FormUrlEncoded a => MimeUnrender FormUrlEncoded (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender JSON a => MimeUnrender JSON (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender OctetStream a => MimeUnrender OctetStream (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbMimeUnrender PlainText a => MimeUnrender PlainText (WithStatus _status a)Defined in servant-0.20.3.0 · Servant.API.UVerbIsServerResource cts a => IsServerResource cts (WithStatus n a)Defined in servant-server-0.20.3.0 · Servant.Server.UVerbEq a => Eq (WithStatus k a)Defined in servant-0.20.3.0 · Servant.API.UVerbShow a => Show (WithStatus k a)Defined in servant-0.20.3.0 · Servant.API.UVerbKnownStatus n => HasStatus (WithStatus n a)Defined in servant-0.20.3.0 · Servant.API.UVerban 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.
type StatusOf (WithStatus n a) = nDefined in servant-0.20.3.0 · Servant.API.UVerbDELETE with 200 status code.
DELETE with 202 status code.
DELETE with 204 status code.
DELETE with 203 status code.
GET with 200 status code.
GET with 202 status code.
GET with 204 status code.
GET with 203 status code.
GET with 206 status code.
GET with 205 status code.
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).
HasLink (NoContentVerb m)Defined in servant-0.20.3.0 · Servant.LinksReflectMethod method => HasServer (NoContentVerb method) contextDefined in servant-server-0.20.3.0 · Servant.Server.InternalGeneric (NoContentVerb method)Defined in servant-0.20.3.0 · Servant.API.Verbstype Rep (NoContentVerb method) = D1 ('MetaData "NoContentVerb"
"Servant.API.Verbs"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) V1Defined in servant-0.20.3.0 · Servant.API.Verbstype MkLink (NoContentVerb m) r = rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (NoContentVerb method) m = m NoContentDefined in servant-server-0.20.3.0 · Servant.Server.InternalPATCH with 200 status code.
PATCH with 202 status code.
PATCH with 204 status code.
PATCH with 203 status code.
POST with 200 status code.
POST with 202 status code.
POST with 201 status code.
POST with 204 status code.
POST with 203 status code.
POST with 205 status code.
PUT with 200 status code.
PUT with 202 status code.
PUT with 201 status code.
PUT with 204 status code.
PUT with 203 status code.
reflectMethod :: Proxy a -> MethodReflectMethod 'CONNECTDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'DELETEDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'GETDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'HEADDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'OPTIONSDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'PATCHDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'POSTDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'PUTDefined in servant-0.20.3.0 · Servant.API.VerbsReflectMethod 'TRACEDefined in servant-0.20.3.0 · Servant.API.VerbsVerb 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:
type Post204 contentTypes a = Verb 'POST 204 contentTypes aHasLink (Verb m s ct a)Defined in servant-0.20.3.0 · Servant.Links(AllCTRender ctypes a, ReflectMethod method, KnownNat status) => HasServer (Verb method status ctypes a) contextDefined in servant-server-0.20.3.0 · 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.3.0 · Servant.Server.InternalGeneric (Verb method statusCode contentTypes a)Defined in servant-0.20.3.0 · Servant.API.VerbsAtMostOneFragment (Verb m s ct typ)Defined in servant-0.20.3.0 · Servant.API.TypeLeveltype Rep (Verb method statusCode contentTypes a) = D1 ('MetaData "Verb"
"Servant.API.Verbs"
"servant-0.20.3.0-D9k5Gr34ZvzEU2YFTfXIf"
'False) V1Defined in servant-0.20.3.0 · Servant.API.Verbstype MkLink (Verb m s ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Verb method status ctypes (Headers h a)) m = m (Headers h a)Defined in servant-server-0.20.3.0 · Servant.Server.Internaltype ServerT (Verb method status ctypes a) m = m aDefined in servant-server-0.20.3.0 · Servant.Server.InternalWithNamedContext 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.
HasLink sub => HasLink (WithNamedContext name context sub)Defined in servant-0.20.3.0 · Servant.Links(HasContextEntry context (NamedContext name subContext), HasServer subApi subContext) => HasServer (WithNamedContext name subContext subApi) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype MkLink (WithNamedContext name context sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (WithNamedContext name subContext subApi) m = ServerT subApi mDefined in servant-server-0.20.3.0 · Servant.Server.InternalHasLink sub => HasLink (WithResource res :> sub)Defined in servant-0.20.3.0 · Servant.Links(HasServer api ctx, HasContextEntry ctx (Acquire a)) => HasServer (WithResource a :> api) ctxDefined in servant-server-0.20.3.0 · 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.
type MkLink (WithResource res :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (WithResource a :> api) m = (ReleaseKey, a) -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalConstruct a toLink for an endpoint.
type family MkLink (endpoint :: k) aTypeError (NoInstanceFor (HasLink api)) => HasLink apiDefined in servant-0.20.3.0 · Servant.LinksHasLink EmptyAPIDefined in servant-0.20.3.0 · Servant.LinksHasLink RawDefined in servant-0.20.3.0 · Servant.LinksHasLink RawMDefined in servant-0.20.3.0 · Servant.Links(HasLink (ToServantApi routes), forall a. GLink routes a, ErrorIfNoGeneric routes) => HasLink (NamedRoutes routes)Defined in servant-0.20.3.0 · Servant.LinksHasLink (NoContentVerb m)Defined in servant-0.20.3.0 · Servant.Links(HasLink a, HasLink b) => HasLink (a :<|> b)Defined in servant-0.20.3.0 · Servant.LinksTypeError (NoInstanceForSub HasLink ty) => HasLink (ty :> sub)Defined in servant-0.20.3.0 · Servant.LinksTypeError (PartialApplication HasLink arr) => HasLink (arr :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink (UVerb m ct a)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (HttpVersion :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (BasicAuth realm a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Description s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Summary s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (AuthProtect tag :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Header' mods sym a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (IsSecure :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (RemoteHost :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (ReqBody' mods ct a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (StreamBody' mods framing ct a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (WithResource res :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Vault :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToDeepQuery record, HasLink sub) => HasLink (DeepQuery sym record :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasLink sub) => HasLink (sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(HasLink sub, ToHttpApiData v) => HasLink (Fragment v :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (WithNamedContext name context sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink (MultiVerb method cs as r)Defined in servant-0.20.3.0 · Servant.LinksHasLink (Verb m s ct a)Defined in servant-0.20.3.0 · Servant.LinksHasLink (Stream m status fr ct a)Defined in servant-0.20.3.0 · Servant.LinksA safe link datatype. The only way of constructing a Link is using safeLink, which means any Link is guaranteed to be part of the mentioned API.
NOTE: If you are writing a custom HasLink instance, and need to manipulate
the Link (adding query params or fragments, perhaps), please use the the
addQueryParam and addSegment functions.
Show LinkDefined in servant-0.20.3.0 · Servant.LinksToHttpApiData LinkDefined in servant-0.20.3.0 · Servant.Linkstype MkLink EmptyAPI a = EmptyAPIDefined in servant-0.20.3.0 · Servant.Linkstype MkLink Raw a = aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink RawM a = aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (HttpVersion :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (BasicAuth realm a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Capture' mods sym v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (CaptureAll sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Description s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Summary s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (AuthProtect tag :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Fragment v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Header' mods sym a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (IsSecure :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (MultiVerb method cs as r) a = aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (NamedRoutes routes) a = routes (AsLink a)Defined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryFlag sym :> sub) a = Bool -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryParam' mods sym v :> sub) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryParams sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (DeepQuery sym record :> sub) a = record -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (RemoteHost :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (ReqBody' mods ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Stream m status fr ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (StreamBody' mods framing ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (UVerb m ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (NoContentVerb m) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Verb m s ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (WithNamedContext name context sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (WithResource res :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Vault :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (a :<|> b) r = MkLink a r :<|> MkLink b rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (arr :> sub) _1 = TypeError (PartialApplication HasLink arr)Defined in servant-0.20.3.0 · Servant.Linkstype MkLink (sym :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.LinksEqP SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.BoolGCompare SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.BoolGEq SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.Boolgeq STrue STrueJust Refl
geq STrue SFalseNothing
GNFData SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.BoolGRead SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.BoolreadsPrec 0 "Some STrue" :: [(Some SBool, String)][(Some STrue,"")]
readsPrec 0 "Some SFalse" :: [(Some SBool, String)][(Some SFalse,"")]
readsPrec 0 "Some Else" :: [(Some SBool, String)][]
GShow SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.BoolshowsPrec 0 STrue """STrue"
OrdP SBoolDefined in singleton-bool-0.1.8 · Data.Singletons.BoolEq (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.BoolOrd (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.BoolShow (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.BoolNFData (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.BoolSBoolI b => Boring (SBool b)Defined in singleton-bool-0.1.8 · Data.Singletons.BoolHasLink sub => HasLink (Vault :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasServer api context => HasServer (Vault :> api) contextDefined in servant-server-0.20.3.0 · Servant.Server.Internaltype MkLink (Vault :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype ServerT (Vault :> api) m = Vault -> ServerT api mDefined in servant-server-0.20.3.0 · Servant.Server.InternalFor implementing servers for servant APIs.
module Servant.Server
Utilities on top of the servant core
allFieldLinks :: (HasLink (ToServantApi routes), GenericServant routes (AsLink Link), ToServant routes (AsLink Link) ~ MkLink (ToServantApi routes) Link) => routes (AsLink Link)Get all links as a record.
More general version of allFieldLinks.
Create all links in an API.
Note that the api type must be restricted to the endpoints that have
valid links to them.
type API = "foo" :> Capture "name" Text :> Get '[JSON] Text :<|> "bar" :> Capture "name" Int :> Get '[JSON] Doublelet fooLink :<|> barLink = allLinks (Proxy :: Proxy API):t fooLinkfooLink :: Text -> Link:t barLinkbarLink :: Int -> Link
Note: nested APIs don't work well with this approach
:kind! MkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double)) LinkMkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double)) Link :: Type= Char -> (Int -> Link) :<|> (Double -> Link)
More general version of fieldLink
type API = "something" :> Get '[JSON] IntlinkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API)something
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
type API = "foo/bar" :> Get '[JSON] IntlinkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API)foo%2Fbar
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}
linkURI $ safeLink someRoute someRoute "test@example.com"abc/test%40example.com
Configurable linkURI.
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
linkURI' LinkArrayElementPlain $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API) [1, 2, 3]sum?x=1&x=2&x=3
safeLink Create a valid (by construction) relative URI with query params.
This function will only typecheck if endpoint is part of the API api
safeLink' More general safeLink.
Represents a general universal resource identifier using its component parts.
For example, for the URI
foo://anonymous@www.haskell.org:42/ghc?query#fragthe components are:
Eq URIDefined in network-uri-2.6.4.2 · Network.URIData URIDefined in network-uri-2.6.4.2 · Network.URIOrd URIDefined in network-uri-2.6.4.2 · Network.URIShow URIDefined in network-uri-2.6.4.2 · Network.URIGeneric URIDefined in network-uri-2.6.4.2 · Network.URINFData URIDefined in network-uri-2.6.4.2 · Network.URIFromJSON URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSONFromJSONKey URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSONToJSON URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.ToJSONToJSONKey URIDefined in aeson-2.3.2.0 · Data.Aeson.Types.ToJSONLift URIDefined in network-uri-2.6.4.2 · Network.URItype Rep URI = D1 ('MetaData "URI"
"Network.URI"
"network-uri-2.6.4.2-1QdlAcNSbcxeQT6IyDD14"
'False) (C1 ('MetaCons "URI"
'PrefixI 'True) ((S1 ('MetaSel ('Just "uriScheme"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "uriAuthority"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (Maybe URIAuth))) :*: (S1 ('MetaSel ('Just "uriPath"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: (S1 ('MetaSel ('Just "uriQuery"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel ('Just "uriFragment"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)))))Defined in network-uri-2.6.4.2 · Network.URIIf both a or b produce an empty constraint, produce an empty constraint.
And () () = ()Append two type-level lists.
AppendList '[] ys = ysAppendList (x ': xs) ys = x ': AppendList xs ysIf there is more than one fragment in an API endpoint, a compile-time error is raised.
type FailAPI = Fragment Bool :> Fragment Int :> Get '[JSON] NoContentinstance AtMostOneFragment FailAPI......Only one Fragment allowed per endpoint in api......
AtMostOneFragment (Fragment a)Defined in servant-0.20.3.0 · Servant.API.TypeLevelAtMostOneFragment (UVerb m cts as)Defined in servant-0.20.3.0 · Servant.API.TypeLevelAtMostOneFragment (Verb m s ct typ)Defined in servant-0.20.3.0 · Servant.API.TypeLevelCheck that a value is an element of a list:
ok (Proxy :: Proxy (Elem Bool '[Int, Bool]))OK
ok (Proxy :: Proxy (Elem String '[Int, Bool]))...... [Char]...'[Int, Bool......
Flatten API into a list of endpoints.
Refl :: Endpoints SampleAPI :~: '["hello" :> Verb 'GET 200 '[JSON] Int, "bye" :> (Capture "name" String :> Verb 'POST 200 '[JSON, PlainText] Bool)]Refl
FragmentUnique (sa :<|> sb) = And (FragmentUnique sa) (FragmentUnique sb)FragmentUnique (Fragment a :> sa) = FragmentNotIn sa (Fragment a :> sa)FragmentUnique (x :> sa) = FragmentUnique saFragmentUnique (Fragment a) = ()FragmentUnique x = ()Closed type family, check if endpoint is within api.
Uses IsElem' if it exhausts all other options.
ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))OK
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:
ok (Proxy :: Proxy (IsElem (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))OK
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).
IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb)IsElem (e :> sa) (e :> sb) = IsElem sa sbIsElem sa (Header sym x :> sb) = IsElem sa sbIsElem sa (Header' mods sym x :> sb) = IsElem sa sbIsElem sa (ReqBody y x :> sb) = IsElem sa sbIsElem (CaptureAll z y :> sa) (CaptureAll x y :> sb) = IsElem sa sbIsElem (Capture z y :> sa) (Capture x y :> sb) = IsElem sa sbIsElem sa (QueryParam x y :> sb) = IsElem sa sbIsElem sa (QueryParams x y :> sb) = IsElem sa sbIsElem sa (QueryFlag x :> sb) = IsElem sa sbIsElem sa (Fragment x :> sb) = IsElem sa sbIsElem (Verb m s ct typ) (Verb m s ct' typ) = IsSubList ct ct'IsElem e e = ()IsElem e (NamedRoutes rs) = IsElem e (ToServantApi rs)IsElem e a = IsElem' e aYou may use this type family to tell the type checker that your custom
type may be skipped as part of a link. This is useful for things like
QueryParam that are optional in a URI and do not affect them if they are
omitted.
data 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.
Closed type family, check if endpoint is exactly within api.
ok (Proxy :: Proxy (IsIn ("hello" :> Get '[JSON] Int) SampleAPI))OK
Unlike IsElem, this requires an *exact* match.
ok (Proxy :: Proxy (IsIn (Get '[JSON] Int) (Header "h" Bool :> Get '[JSON] Int)))...... Could not ......
Check whether sub is a sub-API of api.
ok (Proxy :: Proxy (IsSubAPI SampleAPI (SampleAPI :<|> Get '[JSON] Int)))OK
ok (Proxy :: Proxy (IsSubAPI (SampleAPI :<|> Get '[JSON] Int) SampleAPI))...... Could not ......
This uses IsElem for checking; thus the note there applies here.
A type that specifies that an API record contains a set of links.
GenericMode (AsLink a)Defined in servant-0.20.3.0 · Servant.Linkstype (:-) (AsLink a) api = MkLink api aDefined in servant-0.20.3.0 · Servant.LinksConstruct a toLink for an endpoint.
type family MkLink (endpoint :: k) aTypeError (NoInstanceFor (HasLink api)) => HasLink apiDefined in servant-0.20.3.0 · Servant.LinksHasLink EmptyAPIDefined in servant-0.20.3.0 · Servant.LinksHasLink RawDefined in servant-0.20.3.0 · Servant.LinksHasLink RawMDefined in servant-0.20.3.0 · Servant.Links(HasLink (ToServantApi routes), forall a. GLink routes a, ErrorIfNoGeneric routes) => HasLink (NamedRoutes routes)Defined in servant-0.20.3.0 · Servant.LinksHasLink (NoContentVerb m)Defined in servant-0.20.3.0 · Servant.Links(HasLink a, HasLink b) => HasLink (a :<|> b)Defined in servant-0.20.3.0 · Servant.LinksTypeError (NoInstanceForSub HasLink ty) => HasLink (ty :> sub)Defined in servant-0.20.3.0 · Servant.LinksTypeError (PartialApplication HasLink arr) => HasLink (arr :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink (UVerb m ct a)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (HttpVersion :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (BasicAuth realm a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Description s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Summary s :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (AuthProtect tag :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Header' mods sym a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (IsSecure :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (RemoteHost :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (ReqBody' mods ct a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (StreamBody' mods framing ct a :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (WithResource res :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (Vault :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, ToDeepQuery record, HasLink sub) => HasLink (DeepQuery sym record :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(KnownSymbol sym, HasLink sub) => HasLink (sym :> sub)Defined in servant-0.20.3.0 · Servant.Links(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub)Defined in servant-0.20.3.0 · Servant.Links(HasLink sub, ToHttpApiData v) => HasLink (Fragment v :> sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink sub => HasLink (WithNamedContext name context sub)Defined in servant-0.20.3.0 · Servant.LinksHasLink (MultiVerb method cs as r)Defined in servant-0.20.3.0 · Servant.LinksHasLink (Verb m s ct a)Defined in servant-0.20.3.0 · Servant.LinksHasLink (Stream m status fr ct a)Defined in servant-0.20.3.0 · Servant.LinksA safe link datatype. The only way of constructing a Link is using safeLink, which means any Link is guaranteed to be part of the mentioned API.
NOTE: If you are writing a custom HasLink instance, and need to manipulate
the Link (adding query params or fragments, perhaps), please use the the
addQueryParam and addSegment functions.
Show LinkDefined in servant-0.20.3.0 · Servant.LinksToHttpApiData LinkDefined in servant-0.20.3.0 · Servant.LinksHow to encode array query elements.
LinkArrayElementBracketfoo[]=1&foo[]=2LinkArrayElementPlainfoo=1&foo=2Bounded LinkArrayElementStyleDefined in servant-0.20.3.0 · Servant.LinksEnum LinkArrayElementStyleDefined in servant-0.20.3.0 · Servant.LinksEq LinkArrayElementStyleDefined in servant-0.20.3.0 · Servant.LinksOrd LinkArrayElementStyleDefined in servant-0.20.3.0 · Servant.LinksShow LinkArrayElementStyleDefined in servant-0.20.3.0 · Servant.Linkstype MkLink EmptyAPI a = EmptyAPIDefined in servant-0.20.3.0 · Servant.Linkstype MkLink Raw a = aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink RawM a = aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (HttpVersion :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (BasicAuth realm a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Capture' mods sym v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (CaptureAll sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Description s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Summary s :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (AuthProtect tag :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Fragment v :> sub) a = v -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Header' mods sym a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (IsSecure :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (MultiVerb method cs as r) a = aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (NamedRoutes routes) a = routes (AsLink a)Defined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryFlag sym :> sub) a = Bool -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryParam' mods sym v :> sub) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (QueryParams sym v :> sub) a = [v] -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (DeepQuery sym record :> sub) a = record -> MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (RemoteHost :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (ReqBody' mods ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Stream m status fr ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (StreamBody' mods framing ct a :> sub) r = MkLink sub rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (UVerb m ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (NoContentVerb m) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Verb m s ct a) r = rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (WithNamedContext name context sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (WithResource res :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (Vault :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (a :<|> b) r = MkLink a r :<|> MkLink b rDefined in servant-0.20.3.0 · Servant.Linkstype MkLink (arr :> sub) _1 = TypeError (PartialApplication HasLink arr)Defined in servant-0.20.3.0 · Servant.Linkstype MkLink (sym :> sub) a = MkLink sub aDefined in servant-0.20.3.0 · Servant.LinksQuery parameter.
module Servant.Server.StaticFiles
Useful re-exports
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.
Proxy :: Proxy (Void, Int -> Int)Proxy
Proxy can even hold types of higher kinds,
Proxy :: Proxy EitherProxy
Proxy :: Proxy FunctorProxy
Proxy :: Proxy complicatedStructureProxy
Generic1 ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.GenericsFoldableWithIndex Void ProxyDefined in indexed-traversable-0.1.5 · WithIndexFunctorWithIndex Void ProxyDefined in indexed-traversable-0.1.5 · WithIndexTraversableWithIndex Void ProxyDefined in indexed-traversable-0.1.5 · WithIndexRepeatWithIndex Void ProxyDefined in semialign-1.4 · Data.Semialign.InternalSemialignWithIndex Void ProxyDefined in semialign-1.4 · Data.Semialign.InternalZipWithIndex Void ProxyDefined in semialign-1.4 · Data.Semialign.InternalFilterableWithIndex Void ProxyDefined in witherable-0.5 · WitherableWitherableWithIndex Void ProxyDefined in witherable-0.5 · WitherableEqP ProxyDefined in some-1.1 · Data.EqPOrdP ProxyDefined in some-1.1 · Data.OrdPMonad ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyFunctor ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyApplicative ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyFoldable ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.FoldableTraversable ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.TraversableAlternative ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyMonadPlus ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyMonadZip ProxyDefined in ghc-internal-9.1401.0 · GHC.Internal.Control.Monad.ZipEq1 ProxyDefined in base-4.22.0.0 · Data.Functor.ClassesOrd1 ProxyDefined in base-4.22.0.0 · Data.Functor.ClassesRead1 ProxyDefined in base-4.22.0.0 · Data.Functor.ClassesShow1 ProxyDefined in base-4.22.0.0 · Data.Functor.ClassesContravariant ProxyDefined in base-4.22.0.0 · Data.Functor.ContravariantNFData1 ProxyDefined in deepseq-1.5.1.0 · Control.DeepSeqHashable1 ProxyDefined in hashable-1.5.1.0 · Data.Hashable.ClassDistributive ProxyDefined in distributive-0.6.3 · Data.DistributiveDecidable ProxyDefined in contravariant-1.5.6 · Data.Functor.Contravariant.DivisibleDivisible ProxyDefined in contravariant-1.5.6 · Data.Functor.Contravariant.DivisibleAlt ProxyDefined in semigroupoids-6.0.2 · Data.Functor.AltApply ProxyDefined in semigroupoids-6.0.2 · Data.Functor.Bind.ClassBind ProxyDefined in semigroupoids-6.0.2 · Data.Functor.Bind.ClassExtend ProxyDefined in semigroupoids-6.0.2 · Data.Functor.ExtendConclude ProxyDefined in semigroupoids-6.0.2 · Data.Functor.Contravariant.ConcludeDecide ProxyDefined in semigroupoids-6.0.2 · Data.Functor.Contravariant.DecideDivise ProxyDefined in semigroupoids-6.0.2 · Data.Functor.Contravariant.DivisePlus ProxyDefined in semigroupoids-6.0.2 · Data.Functor.PlusAlign ProxyDefined in semialign-1.4 · Data.Semialign.InternalSemialign ProxyDefined in semialign-1.4 · Data.Semialign.InternalUnalign ProxyDefined in semialign-1.4 · Data.Semialign.InternalRepeat ProxyDefined in semialign-1.4 · Data.Semialign.InternalUnzip ProxyDefined in semialign-1.4 · Data.Semialign.InternalZip ProxyDefined in semialign-1.4 · Data.Semialign.InternalFilterable ProxyDefined in witherable-0.5 · WitherableWitherable ProxyDefined in witherable-0.5 · WitherableFromJSON1 ProxyDefined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSONToJSON1 ProxyDefined in aeson-2.3.2.0 · Data.Aeson.Types.ToJSONBounded (Proxy t)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyEnum (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyEq (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyData t => Data (Proxy t)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.DataOrd (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyRead (Proxy t)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyShow (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyIx (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyGeneric (Proxy t)Defined in ghc-internal-9.1401.0 · GHC.Internal.GenericsSemigroup (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyMonoid (Proxy s)Defined in ghc-internal-9.1401.0 · GHC.Internal.Data.ProxyNFData (Proxy a)Defined in deepseq-1.5.1.0 · Control.DeepSeqHashable (Proxy a)Defined in hashable-1.5.1.0 · Data.Hashable.ClassFromJSON (Proxy a)Defined in aeson-2.3.2.0 · Data.Aeson.Types.FromJSONToJSON (Proxy a)Defined in aeson-2.3.2.0 · Data.Aeson.Types.ToJSONDefault (Proxy a)Defined in data-default-0.8.0.2 · Data.Default.InternalBoring (Proxy a)Defined in boring-0.2.2.1 · Data.BoringGeneric (Proxy t)Defined in generics-sop-0.5.1.4 · Generics.SOP.Instances · orphanHasDatatypeInfo (Proxy t)Defined in generics-sop-0.5.1.4 · Generics.SOP.Instances · orphantype Rep (Proxy t) = D1 ('MetaData "Proxy"
"GHC.Internal.Data.Proxy"
"ghc-internal"
'False) (C1 ('MetaCons "Proxy"
'PrefixI 'False) U1)Defined in ghc-internal-9.1401.0 · GHC.Internal.Genericstype Rep1 Proxy = D1 ('MetaData "Proxy"
"GHC.Internal.Data.Proxy"
"ghc-internal"
'False) (C1 ('MetaCons "Proxy"
'PrefixI 'False) U1)Defined in ghc-internal-9.1401.0 · GHC.Internal.Genericstype Code (Proxy t) = '['[]]Defined in generics-sop-0.5.1.4 · Generics.SOP.Instances · orphantype DatatypeInfoOf (Proxy t) = 'ADT "GHC.Internal.Data.Proxy"
"Proxy"
'['Constructor "Proxy"
] '['[]]Defined in generics-sop-0.5.1.4 · Generics.SOP.Instances · orphanIs used within a monadic computation to begin exception processing.