Safe Haskell | Trustworthy |
---|---|
Language | Haskell2010 |
A Dropwizard-inspired web framework that integrates Servant, monad-metricsEKG, monad-loggerfast-logger, and other useful libraries to provide a smooth web service development experience.
This module provides all the stuff you need for an application: - reexports from all the modules below, including orphan instances from Magicbane.Has - orphan instances for RIO - reexports from various utility packages - a basic example context for simple apps
Synopsis
- assert :: Bool -> a -> a
- class Typeable (a :: k)
- eitherDecodeFileStrict' :: FromJSON a => FilePath -> IO (Either String a)
- eitherDecodeStrict' :: FromJSON a => ByteString -> Either String a
- eitherDecode' :: FromJSON a => ByteString -> Either String a
- eitherDecodeFileStrict :: FromJSON a => FilePath -> IO (Either String a)
- eitherDecodeStrict :: FromJSON a => ByteString -> Either String a
- eitherDecode :: FromJSON a => ByteString -> Either String a
- decodeFileStrict' :: FromJSON a => FilePath -> IO (Maybe a)
- decodeStrict' :: FromJSON a => ByteString -> Maybe a
- decode' :: FromJSON a => ByteString -> Maybe a
- decodeFileStrict :: FromJSON a => FilePath -> IO (Maybe a)
- decodeStrict :: FromJSON a => ByteString -> Maybe a
- decode :: FromJSON a => ByteString -> Maybe a
- encodeFile :: ToJSON a => FilePath -> a -> IO ()
- encode :: ToJSON a => a -> ByteString
- foldable :: (Foldable t, ToJSON a) => t a -> Encoding
- type GToJSON = GToJSON Value
- type GToEncoding = GToJSON Encoding
- toEncoding2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Encoding
- toJSON2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Value
- toEncoding1 :: (ToJSON1 f, ToJSON a) => f a -> Encoding
- toJSON1 :: (ToJSON1 f, ToJSON a) => f a -> Value
- genericLiftToEncoding :: (Generic1 f, GToJSON Encoding One (Rep1 f)) => Options -> (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding
- genericToEncoding :: (Generic a, GToJSON Encoding Zero (Rep a)) => Options -> a -> Encoding
- genericLiftToJSON :: (Generic1 f, GToJSON Value One (Rep1 f)) => Options -> (a -> Value) -> ([a] -> Value) -> f a -> Value
- genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value
- data ToArgs res arity a where
- class ToJSON a where
- class KeyValue kv where
- class ToJSONKey a where
- data ToJSONKeyFunction a
- = ToJSONKeyText !(a -> Text) !(a -> Encoding' Text)
- | ToJSONKeyValue !(a -> Value) !(a -> Encoding)
- class ToJSON1 (f :: * -> *) where
- class ToJSON2 (f :: * -> * -> *) where
- pairs :: Series -> Encoding
- fromEncoding :: Encoding' tag -> Builder
- type Encoding = Encoding' Value
- data Series
- (.!=) :: Parser (Maybe a) -> a -> Parser a
- (.:!) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a)
- (.:) :: FromJSON a => Object -> Text -> Parser a
- fromJSON :: FromJSON a => Value -> Result a
- withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a
- withBool :: String -> (Bool -> Parser a) -> Value -> Parser a
- withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a
- withArray :: String -> (Array -> Parser a) -> Value -> Parser a
- withText :: String -> (Text -> Parser a) -> Value -> Parser a
- withObject :: String -> (Object -> Parser a) -> Value -> Parser a
- parseJSON2 :: (FromJSON2 f, FromJSON a, FromJSON b) => Value -> Parser (f a b)
- parseJSON1 :: (FromJSON1 f, FromJSON a) => Value -> Parser (f a)
- genericLiftParseJSON :: (Generic1 f, GFromJSON One (Rep1 f)) => Options -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a)
- genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a
- class GFromJSON arity (f :: * -> *) where
- data FromArgs arity a where
- class FromJSON a where
- class FromJSONKey a where
- data FromJSONKeyFunction a
- = FromJSONKeyCoerce !(CoerceText a)
- | FromJSONKeyText !(Text -> a)
- | FromJSONKeyTextParser !(Text -> Parser a)
- | FromJSONKeyValue !(Value -> Parser a)
- class FromJSON1 (f :: * -> *) where
- class FromJSON2 (f :: * -> * -> *) where
- json' :: Parser Value
- json :: Parser Value
- camelTo2 :: Char -> String -> String
- defaultTaggedObject :: SumEncoding
- defaultOptions :: Options
- object :: [Pair] -> Value
- data Result a
- type Object = HashMap Text Value
- type Array = Vector Value
- data Value
- newtype DotNetTime = DotNetTime {}
- data Options
- data SumEncoding
- data Zero
- data One
- aesonQQ :: QuasiQuoter
- data ThreadId
- rtsSupportsBoundThreads :: Bool
- data Chan a
- data SomeAsyncException where
- data IOException
- class (Typeable e, Show e) => Exception e where
- asProxyTypeOf :: a -> proxy a -> a
- data Proxy (t :: k) :: forall k. k -> * = Proxy
- data KProxy t = KProxy
- type family If (cond :: Bool) (tru :: k) (fls :: k) :: k where ...
- data MVar a
- data SomeException where
- newtype MaybeT (m :: * -> *) a = MaybeT {}
- newtype ExceptT e (m :: * -> *) a = ExceptT (m (Either e a))
- class MonadIO m => MonadUnliftIO (m :: * -> *)
- class Has a t where
- registerGcMetrics :: Store -> IO ()
- data Store
- serverMetricStore :: Server -> Store
- showEnv :: IO ()
- unsetEnvironment' :: ToEnv a => a -> IO (Either String ())
- unsetEnvironment :: EnvList a -> IO (Either String ())
- setEnvironment' :: ToEnv a => a -> IO (Either String ())
- setEnvironment :: EnvList a -> IO (Either String ())
- decodeEnv :: FromEnv a => IO (Either String a)
- makeEnv :: [EnvVar] -> EnvList a
- gFromEnvCustom :: (DefConfig a, Generic a, GFromEnv (Rep a)) => Option -> Parser a
- envMaybe :: Var a => String -> Parser (Maybe a)
- env :: Var a => String -> Parser a
- runEnv :: Parser a -> IO (Either String a)
- newtype Parser a = Parser {}
- class FromEnv a where
- class DefConfig a where
- data Option = Option {}
- class ToEnv a where
- data EnvList a
- class Typeable a => Var a where
- fmapRT :: Monad m => (a -> b) -> ExceptT l m a -> ExceptT l m b
- isRightT :: Monad m => ExceptT a m b -> m Bool
- isLeftT :: Monad m => ExceptT a m b -> m Bool
- fmapR :: (a -> b) -> Either l a -> Either l b
- isRight :: Either a b -> Bool
- isLeft :: Either a b -> Bool
- isNothingT :: Monad m => MaybeT m a -> m Bool
- isJustT :: Monad m => MaybeT m a -> m Bool
- nothing :: Monad m => MaybeT m a
- just :: Monad m => a -> MaybeT m a
- maybeT :: Monad m => m b -> (a -> m b) -> MaybeT m a -> m b
- failWithM :: Applicative m => e -> m (Maybe a) -> ExceptT e m a
- failWith :: Applicative m => e -> Maybe a -> ExceptT e m a
- (?:) :: Maybe a -> a -> a
- (!?) :: Applicative m => m (Maybe a) -> e -> ExceptT e m a
- hoistMaybe :: Monad m => Maybe b -> MaybeT m b
- noteT :: Monad m => a -> MaybeT m b -> ExceptT a m b
- note :: a -> Maybe b -> Either a b
- hushT :: Monad m => ExceptT a m b -> MaybeT m b
- hush :: Either a b -> Maybe b
- hoistEither :: Monad m => Either e a -> ExceptT e m a
- bimapExceptT :: Functor m => (e -> f) -> (a -> b) -> ExceptT e m a -> ExceptT f m b
- exceptT :: Monad m => (a -> m c) -> (b -> m c) -> ExceptT a m b -> m c
- newtype AllE e r = AllE {}
- newtype AnyE e r = AnyE {}
- mapMaybeT :: (m (Maybe a) -> n (Maybe b)) -> MaybeT m a -> MaybeT n b
- liftCatch :: Catch e m (Maybe a) -> Catch e (MaybeT m) a
- runExceptT :: ExceptT e m a -> m (Either e a)
- class MonadThrow m => MonadCatch (m :: * -> *)
- data LogType
- = LogNone
- | LogStdout BufSize
- | LogStderr BufSize
- | LogFileNoRotate FilePath BufSize
- | LogFile FileLogSpec BufSize
- | LogCallback (LogStr -> IO ()) (IO ())
- defaultBufSize :: BufSize
- encodePathSegmentsRelative :: [Text] -> Builder
- class ToHttpApiData a where
- class FromHttpApiData a where
- data URI = URI {}
- responseTimeoutDefault :: ResponseTimeout
- responseTimeoutNone :: ResponseTimeout
- responseTimeoutMicro :: Int -> ResponseTimeout
- managerSetProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
- managerSetSecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
- managerSetInsecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings
- withResponseHistory :: Request -> Manager -> (HistoriedResponse BodyReader -> IO a) -> IO a
- responseOpenHistory :: Request -> Manager -> IO (HistoriedResponse BodyReader)
- data HistoriedResponse body
- withConnection :: Request -> Manager -> (Connection -> IO a) -> IO a
- responseClose :: Response a -> IO ()
- responseOpen :: Request -> Manager -> IO (Response BodyReader)
- httpNoBody :: Request -> Manager -> IO (Response ())
- httpLbs :: Request -> Manager -> IO (Response ByteString)
- withResponse :: Request -> Manager -> (Response BodyReader -> IO a) -> IO a
- generateCookie :: SetCookie -> Request -> UTCTime -> Bool -> Maybe Cookie
- insertCheckedCookie :: Cookie -> CookieJar -> Bool -> CookieJar
- receiveSetCookie :: SetCookie -> Request -> UTCTime -> Bool -> CookieJar -> CookieJar
- updateCookieJar :: Response a -> Request -> UTCTime -> CookieJar -> (CookieJar, Response a)
- computeCookieString :: Request -> CookieJar -> UTCTime -> Bool -> (ByteString, CookieJar)
- insertCookiesIntoRequest :: Request -> CookieJar -> UTCTime -> (Request, CookieJar)
- evictExpiredCookies :: CookieJar -> UTCTime -> CookieJar
- removeExistingCookieFromCookieJar :: Cookie -> CookieJar -> (Maybe Cookie, CookieJar)
- destroyCookieJar :: CookieJar -> [Cookie]
- createCookieJar :: [Cookie] -> CookieJar
- pathMatches :: ByteString -> ByteString -> Bool
- defaultPath :: Request -> ByteString
- domainMatches :: ByteString -> ByteString -> Bool
- isIpAddress :: ByteString -> Bool
- defaultProxy :: ProxyOverride
- proxyEnvironmentNamed :: Text -> Maybe Proxy -> ProxyOverride
- proxyEnvironment :: Maybe Proxy -> ProxyOverride
- useProxy :: Proxy -> ProxyOverride
- noProxy :: ProxyOverride
- proxyFromRequest :: ProxyOverride
- withManager :: ManagerSettings -> (Manager -> IO a) -> IO a
- closeManager :: Manager -> IO ()
- newManager :: ManagerSettings -> IO Manager
- defaultManagerSettings :: ManagerSettings
- rawConnectionModifySocketSize :: (Socket -> IO ()) -> IO (Int -> Maybe HostAddress -> String -> Int -> IO Connection)
- rawConnectionModifySocket :: (Socket -> IO ()) -> IO (Maybe HostAddress -> String -> Int -> IO Connection)
- observedStreamFile :: (StreamFileStatus -> IO ()) -> FilePath -> IO RequestBody
- streamFile :: FilePath -> IO RequestBody
- setQueryStringPartialEscape :: [(ByteString, [EscapeItem])] -> Request -> Request
- setQueryString :: [(ByteString, Maybe ByteString)] -> Request -> Request
- setRequestCheckStatus :: Request -> Request
- setRequestIgnoreStatus :: Request -> Request
- urlEncodedBody :: [(ByteString, ByteString)] -> Request -> Request
- applyBasicProxyAuth :: ByteString -> ByteString -> Request -> Request
- applyBasicAuth :: ByteString -> ByteString -> Request -> Request
- defaultRequest :: Request
- getUri :: Request -> URI
- requestFromURI_ :: URI -> Request
- requestFromURI :: MonadThrow m => URI -> m Request
- parseRequest_ :: String -> Request
- parseRequest :: MonadThrow m => String -> m Request
- throwErrorStatusCodes :: MonadIO m => Request -> Response BodyReader -> m ()
- parseUrlThrow :: MonadThrow m => String -> m Request
- parseUrl :: MonadThrow m => String -> m Request
- brConsume :: BodyReader -> IO [ByteString]
- brReadSome :: BodyReader -> Int -> IO ByteString
- brRead :: BodyReader -> IO ByteString
- socketConnection :: Socket -> Int -> IO Connection
- makeConnection :: IO ByteString -> (ByteString -> IO ()) -> IO () -> IO Connection
- type BodyReader = IO ByteString
- data HttpException
- data HttpExceptionContent
- = StatusCodeException (Response ()) ByteString
- | TooManyRedirects [Response ByteString]
- | OverlongHeaders
- | ResponseTimeout
- | ConnectionTimeout
- | ConnectionFailure SomeException
- | InvalidStatusLine ByteString
- | InvalidHeader ByteString
- | InternalException SomeException
- | ProxyConnectException ByteString Int Status
- | NoResponseDataReceived
- | TlsNotSupported
- | WrongRequestBodyStreamSize Word64 Word64
- | ResponseBodyTooShort Word64 Word64
- | InvalidChunkHeaders
- | IncompleteHeaders
- | InvalidDestinationHost ByteString
- | HttpZlibException ZlibException
- | InvalidProxyEnvironmentVariable Text Text
- | ConnectionClosed
- | InvalidProxySettings Text
- data Cookie = Cookie {}
- data CookieJar
- proxyHost :: Proxy -> ByteString
- proxyPort :: Proxy -> Int
- data RequestBody
- type Popper = IO ByteString
- type NeedsPopper a = Popper -> IO a
- type GivesPopper a = NeedsPopper a -> IO a
- data Request
- data ResponseTimeout
- data Response body
- data ManagerSettings
- data ProxyOverride
- data Manager
- class HasHttpManager a where
- data StreamFileStatus = StreamFileStatus {}
- type Query = [QueryItem]
- writeLinkHeader :: [Link] -> Text
- writeLink :: Link -> Text
- parseLinkHeaderBS :: ByteString -> Maybe [Link]
- parseLinkHeaderBS' :: ByteString -> Either String [Link]
- parseLinkHeader :: Text -> Maybe [Link]
- parseLinkHeader' :: Text -> Either String [Link]
- linkHeader :: Parser [Link]
- lnk :: String -> [(LinkParam, Text)] -> Maybe Link
- linkParams :: Link -> [(LinkParam, Text)]
- href :: Link -> URI
- data LinkParam
- http20 :: HttpVersion
- http11 :: HttpVersion
- http10 :: HttpVersion
- http09 :: HttpVersion
- data HttpVersion = HttpVersion {}
- class QueryLike a where
- renderQueryBuilderPartialEscape :: Bool -> PartialEscapeQuery -> Builder
- renderQueryPartialEscape :: Bool -> PartialEscapeQuery -> ByteString
- decodePath :: ByteString -> ([Text], Query)
- encodePath :: [Text] -> Query -> Builder
- extractPath :: ByteString -> ByteString
- decodePathSegments :: ByteString -> [Text]
- encodePathSegments :: [Text] -> Builder
- urlDecode :: Bool -> ByteString -> ByteString
- urlEncode :: Bool -> ByteString -> ByteString
- urlEncodeBuilder :: Bool -> ByteString -> Builder
- parseSimpleQuery :: ByteString -> SimpleQuery
- parseQuery :: ByteString -> Query
- renderSimpleQuery :: Bool -> SimpleQuery -> ByteString
- renderQuery :: Bool -> Query -> ByteString
- renderQueryBuilder :: Bool -> Query -> Builder
- simpleQueryToQuery :: SimpleQuery -> Query
- parseQueryText :: ByteString -> QueryText
- queryToQueryText :: Query -> QueryText
- renderQueryText :: Bool -> QueryText -> Builder
- queryTextToQuery :: QueryText -> Query
- type QueryItem = (ByteString, Maybe ByteString)
- type QueryText = [(Text, Maybe Text)]
- type SimpleQueryItem = (ByteString, ByteString)
- type SimpleQuery = [SimpleQueryItem]
- data EscapeItem
- = QE ByteString
- | QN ByteString
- type PartialEscapeQueryItem = (ByteString, [EscapeItem])
- type PartialEscapeQuery = [PartialEscapeQueryItem]
- statusIsServerError :: Status -> Bool
- statusIsClientError :: Status -> Bool
- statusIsRedirection :: Status -> Bool
- statusIsSuccessful :: Status -> Bool
- statusIsInformational :: Status -> Bool
- networkAuthenticationRequired511 :: Status
- status511 :: Status
- httpVersionNotSupported505 :: Status
- status505 :: Status
- gatewayTimeout504 :: Status
- status504 :: Status
- serviceUnavailable503 :: Status
- status503 :: Status
- badGateway502 :: Status
- status502 :: Status
- notImplemented501 :: Status
- status501 :: Status
- internalServerError500 :: Status
- status500 :: Status
- requestHeaderFieldsTooLarge431 :: Status
- status431 :: Status
- tooManyRequests429 :: Status
- status429 :: Status
- preconditionRequired428 :: Status
- status428 :: Status
- unprocessableEntity422 :: Status
- status422 :: Status
- imATeapot418 :: Status
- status418 :: Status
- expectationFailed417 :: Status
- status417 :: Status
- requestedRangeNotSatisfiable416 :: Status
- status416 :: Status
- unsupportedMediaType415 :: Status
- status415 :: Status
- requestURITooLong414 :: Status
- status414 :: Status
- requestEntityTooLarge413 :: Status
- status413 :: Status
- preconditionFailed412 :: Status
- status412 :: Status
- lengthRequired411 :: Status
- status411 :: Status
- gone410 :: Status
- status410 :: Status
- conflict409 :: Status
- status409 :: Status
- requestTimeout408 :: Status
- status408 :: Status
- proxyAuthenticationRequired407 :: Status
- status407 :: Status
- notAcceptable406 :: Status
- status406 :: Status
- methodNotAllowed405 :: Status
- status405 :: Status
- notFound404 :: Status
- status404 :: Status
- forbidden403 :: Status
- status403 :: Status
- paymentRequired402 :: Status
- status402 :: Status
- unauthorized401 :: Status
- status401 :: Status
- badRequest400 :: Status
- status400 :: Status
- permanentRedirect308 :: Status
- status308 :: Status
- temporaryRedirect307 :: Status
- status307 :: Status
- useProxy305 :: Status
- status305 :: Status
- notModified304 :: Status
- status304 :: Status
- seeOther303 :: Status
- status303 :: Status
- found302 :: Status
- status302 :: Status
- movedPermanently301 :: Status
- status301 :: Status
- multipleChoices300 :: Status
- status300 :: Status
- partialContent206 :: Status
- status206 :: Status
- resetContent205 :: Status
- status205 :: Status
- noContent204 :: Status
- status204 :: Status
- nonAuthoritative203 :: Status
- status203 :: Status
- accepted202 :: Status
- status202 :: Status
- created201 :: Status
- status201 :: Status
- ok200 :: Status
- status200 :: Status
- switchingProtocols101 :: Status
- status101 :: Status
- continue100 :: Status
- status100 :: Status
- mkStatus :: Int -> ByteString -> Status
- data Status = Status {}
- renderStdMethod :: StdMethod -> Method
- renderMethod :: Either ByteString StdMethod -> Method
- parseMethod :: Method -> Either ByteString StdMethod
- methodPatch :: Method
- methodOptions :: Method
- methodConnect :: Method
- methodTrace :: Method
- methodDelete :: Method
- methodPut :: Method
- methodHead :: Method
- methodPost :: Method
- methodGet :: Method
- type Method = ByteString
- data StdMethod
- parseByteRanges :: ByteString -> Maybe ByteRanges
- renderByteRanges :: ByteRanges -> ByteString
- renderByteRangesBuilder :: ByteRanges -> Builder
- renderByteRange :: ByteRange -> ByteString
- renderByteRangeBuilder :: ByteRange -> Builder
- hCookie :: HeaderName
- hUserAgent :: HeaderName
- hServer :: HeaderName
- hReferer :: HeaderName
- hRange :: HeaderName
- hLocation :: HeaderName
- hLastModified :: HeaderName
- hIfRange :: HeaderName
- hIfModifiedSince :: HeaderName
- hDate :: HeaderName
- hContentType :: HeaderName
- hContentMD5 :: HeaderName
- hContentLength :: HeaderName
- hContentEncoding :: HeaderName
- hConnection :: HeaderName
- hCacheControl :: HeaderName
- hAuthorization :: HeaderName
- hAcceptLanguage :: HeaderName
- hAccept :: HeaderName
- type HeaderName = CI ByteString
- type RequestHeaders = [Header]
- type ResponseHeaders = [Header]
- data ByteRange
- type ByteRanges = [ByteRange]
- label' :: (MonadIO m, MonadMetrics m, Show a) => Text -> a -> m ()
- label :: (MonadIO m, MonadMetrics m) => Text -> Text -> m ()
- timed :: (MonadIO m, MonadMetrics m, MonadMask m) => Text -> m a -> m a
- timedList :: (MonadIO m, MonadMetrics m, MonadMask m) => Resolution -> [Text] -> m a -> m a
- timed' :: (MonadIO m, MonadMetrics m, MonadMask m) => Resolution -> Text -> m a -> m a
- gauge :: (MonadIO m, MonadMetrics m) => Text -> Int -> m ()
- gauge' :: (MonadIO m, MonadMetrics m, Integral int) => Text -> int -> m ()
- distribution :: (MonadIO m, MonadMetrics m) => Text -> Double -> m ()
- counter :: (MonadIO m, MonadMetrics m) => Text -> Int -> m ()
- counter' :: (MonadIO m, MonadMetrics m, Integral int) => Text -> int -> m ()
- increment :: (MonadIO m, MonadMetrics m) => Text -> m ()
- class Monad m => MonadMetrics (m :: * -> *) where
- metricsStore :: Lens' Metrics Store
- metricsLabels :: Lens' Metrics (IORef (HashMap Text Label))
- metricsGauges :: Lens' Metrics (IORef (HashMap Text Gauge))
- metricsCounters :: Lens' Metrics (IORef (HashMap Text Counter))
- data Metrics
- data Resolution
- throwError :: MonadError e m => e -> m a
- fragment :: URI -> String
- query :: URI -> String
- path :: URI -> String
- authority :: URI -> String
- scheme :: URI -> String
- unreserved :: Char -> Bool
- reserved :: Char -> Bool
- escapeString :: String -> (Char -> Bool) -> String
- parseabsoluteURI :: String -> Maybe URI
- normalizePathSegments :: String -> String
- normalizeEscape :: String -> String
- normalizeCase :: String -> String
- relativeFrom :: URI -> URI -> URI
- pathSegments :: URI -> [String]
- relativeTo :: URI -> URI -> URI
- nonStrictRelativeTo :: URI -> URI -> URI
- unEscapeString :: String -> String
- escapeURIString :: (Char -> Bool) -> String -> String
- escapeURIChar :: (Char -> Bool) -> Char -> String
- isUnescapedInURIComponent :: Char -> Bool
- isUnescapedInURI :: Char -> Bool
- isAllowedInURI :: Char -> Bool
- uriToString :: (String -> String) -> URI -> ShowS
- isUnreserved :: Char -> Bool
- isReserved :: Char -> Bool
- uriIsRelative :: URI -> Bool
- uriIsAbsolute :: URI -> Bool
- isIPv4address :: String -> Bool
- isIPv6address :: String -> Bool
- isAbsoluteURI :: String -> Bool
- isRelativeReference :: String -> Bool
- isURIReference :: String -> Bool
- isURI :: String -> Bool
- parseAbsoluteURI :: String -> Maybe URI
- parseRelativeReference :: String -> Maybe URI
- parseURIReference :: String -> Maybe URI
- parseURI :: String -> Maybe URI
- nullURI :: URI
- data URIAuth = URIAuth {
- uriUserInfo :: String
- uriRegName :: String
- uriPort :: String
- rQ :: QuasiQuoter
- r :: QuasiQuoter
- throwRefineOtherException :: Monad m => TypeRep -> Doc Void -> RefineT m a
- catchRefine :: Monad m => RefineT m a -> (RefineException -> RefineT m a) -> RefineT m a
- throwRefine :: Monad m => RefineException -> RefineT m a
- runRefineM :: RefineM a -> Either RefineException a
- refineM :: Either RefineException a -> RefineM a
- mapRefineT :: (m (Either RefineException a) -> n (Either RefineException b)) -> RefineT m a -> RefineT n b
- runRefineT :: RefineT m a -> m (Either RefineException a)
- displayRefineException :: RefineException -> Doc ann
- rightOr :: Refined r x -> Refined (Or l r) x
- leftOr :: Refined l x -> Refined (Or l r) x
- andRight :: Refined (And l r) x -> Refined r x
- andLeft :: Refined (And l r) x -> Refined l x
- unrefine :: Refined p x -> x
- refineTH :: (Predicate p x, Lift x) => x -> Q (TExp (Refined p x))
- unsafeRefine :: Predicate p x => x -> Refined p x
- refineError :: (Predicate p x, MonadError RefineException m) => x -> m (Refined p x)
- refineFail :: (Predicate p x, MonadFail m) => x -> m (Refined p x)
- refineThrow :: (Predicate p x, MonadThrow m) => x -> m (Refined p x)
- refine :: Predicate p x => x -> Either RefineException (Refined p x)
- data Refined p x
- class Typeable p => Predicate p x where
- data Not p
- data And l r
- type (&&) = And
- data Or l r
- type (||) = Or
- data SizeLessThan (n :: Nat)
- data SizeGreaterThan (n :: Nat)
- data SizeEqualTo (n :: Nat)
- data Ascending
- data Descending
- data LessThan (n :: Nat)
- data GreaterThan (n :: Nat)
- data From (n :: Nat)
- data To (n :: Nat)
- data FromTo (mn :: Nat) (mx :: Nat)
- data EqualTo (n :: Nat)
- data NotEqualTo (n :: Nat)
- type Positive = GreaterThan 0
- type NonPositive = To 0
- type Negative = LessThan 0
- type NonNegative = From 0
- type ZeroToOne = FromTo 0 1
- type NonZero = NotEqualTo 0
- type NonEmpty = SizeGreaterThan 0
- class Weaken from to where
- data RefineException
- data RefineT (m :: * -> *) a
- type RefineM a = RefineT Identity a
- newChan :: MonadIO m => m (Chan a)
- writeChan :: MonadIO m => Chan a -> a -> m ()
- readChan :: MonadIO m => Chan a -> m a
- dupChan :: MonadIO m => Chan a -> m (Chan a)
- getChanContents :: MonadIO m => Chan a -> m [a]
- writeList2Chan :: MonadIO m => Chan a -> [a] -> m ()
- data StringException = StringException String CallStack
- data AsyncExceptionWrapper where
- data SyncExceptionWrapper where
- catch :: (MonadUnliftIO m, Exception e) => m a -> (e -> m a) -> m a
- catchIO :: MonadUnliftIO m => m a -> (IOException -> m a) -> m a
- catchAny :: MonadUnliftIO m => m a -> (SomeException -> m a) -> m a
- catchDeep :: (MonadUnliftIO m, Exception e, NFData a) => m a -> (e -> m a) -> m a
- catchAnyDeep :: (NFData a, MonadUnliftIO m) => m a -> (SomeException -> m a) -> m a
- catchJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> m a -> (b -> m a) -> m a
- handle :: (MonadUnliftIO m, Exception e) => (e -> m a) -> m a -> m a
- handleIO :: MonadUnliftIO m => (IOException -> m a) -> m a -> m a
- handleAny :: MonadUnliftIO m => (SomeException -> m a) -> m a -> m a
- handleDeep :: (MonadUnliftIO m, Exception e, NFData a) => (e -> m a) -> m a -> m a
- handleAnyDeep :: (MonadUnliftIO m, NFData a) => (SomeException -> m a) -> m a -> m a
- handleJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a
- try :: (MonadUnliftIO m, Exception e) => m a -> m (Either e a)
- tryIO :: MonadUnliftIO m => m a -> m (Either IOException a)
- tryAny :: MonadUnliftIO m => m a -> m (Either SomeException a)
- tryDeep :: (MonadUnliftIO m, Exception e, NFData a) => m a -> m (Either e a)
- tryAnyDeep :: (MonadUnliftIO m, NFData a) => m a -> m (Either SomeException a)
- tryJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a)
- pureTry :: a -> Either SomeException a
- pureTryDeep :: NFData a => a -> Either SomeException a
- catches :: MonadUnliftIO m => m a -> [Handler m a] -> m a
- catchesDeep :: (MonadUnliftIO m, NFData a) => m a -> [Handler m a] -> m a
- evaluate :: MonadIO m => a -> m a
- evaluateDeep :: (MonadIO m, NFData a) => a -> m a
- bracket :: MonadUnliftIO m => m a -> (a -> m b) -> (a -> m c) -> m c
- bracket_ :: MonadUnliftIO m => m a -> m b -> m c -> m c
- bracketOnError :: MonadUnliftIO m => m a -> (a -> m b) -> (a -> m c) -> m c
- bracketOnError_ :: MonadUnliftIO m => m a -> m b -> m c -> m c
- finally :: MonadUnliftIO m => m a -> m b -> m a
- withException :: (MonadUnliftIO m, Exception e) => m a -> (e -> m b) -> m a
- onException :: MonadUnliftIO m => m a -> m b -> m a
- throwIO :: (MonadIO m, Exception e) => e -> m a
- toSyncException :: Exception e => e -> SomeException
- toAsyncException :: Exception e => e -> SomeException
- isSyncException :: Exception e => e -> Bool
- isAsyncException :: Exception e => e -> Bool
- mask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m b) -> m b
- uninterruptibleMask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m b) -> m b
- mask_ :: MonadUnliftIO m => m a -> m a
- uninterruptibleMask_ :: MonadUnliftIO m => m a -> m a
- throwString :: (MonadIO m, HasCallStack) => String -> m a
- stringException :: HasCallStack -> String -> StringException
- throwTo :: (Exception e, MonadIO m) => ThreadId -> e -> m ()
- impureThrow :: Exception e => e -> a
- fromEither :: (Exception e, MonadIO m) => Either e a -> m a
- fromEitherIO :: (Exception e, MonadIO m) => IO (Either e a) -> m a
- fromEitherM :: (Exception e, MonadIO m) => m (Either e a) -> m a
- newEmptyMVar :: MonadIO m => m (MVar a)
- newMVar :: MonadIO m => a -> m (MVar a)
- takeMVar :: MonadIO m => MVar a -> m a
- putMVar :: MonadIO m => MVar a -> a -> m ()
- readMVar :: MonadIO m => MVar a -> m a
- swapMVar :: MonadIO m => MVar a -> a -> m a
- tryTakeMVar :: MonadIO m => MVar a -> m (Maybe a)
- tryPutMVar :: MonadIO m => MVar a -> a -> m Bool
- isEmptyMVar :: MonadIO m => MVar a -> m Bool
- tryReadMVar :: MonadIO m => MVar a -> m (Maybe a)
- withMVar :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b
- withMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b
- modifyMVar_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m ()
- modifyMVar :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b
- modifyMVarMasked_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m ()
- modifyMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b
- mkWeakMVar :: MonadUnliftIO m => MVar a -> m () -> m (Weak (MVar a))
- data RIO env a
- myThreadId :: MonadIO m => m ThreadId
- threadDelay :: MonadIO m => Int -> m ()
- threadWaitRead :: MonadIO m => Fd -> m ()
- threadWaitWrite :: MonadIO m => Fd -> m ()
- isCurrentThreadBound :: MonadIO m => m Bool
- allFieldLinks' :: (HasLink (ToServantApi routes), GenericServant routes (AsLink a), ToServant routes (AsLink a) ~ MkLink (ToServantApi routes) a) => (Link -> a) -> routes (AsLink a)
- allFieldLinks :: (HasLink (ToServantApi routes), GenericServant routes (AsLink Link), ToServant routes (AsLink Link) ~ MkLink (ToServantApi routes) Link) => routes (AsLink Link)
- fieldLink' :: (IsElem endpoint (ToServantApi routes), HasLink endpoint, GenericServant routes AsApi) => (Link -> a) -> (routes AsApi -> endpoint) -> MkLink endpoint a
- fieldLink :: (IsElem endpoint (ToServantApi routes), HasLink endpoint, GenericServant routes AsApi) => (routes AsApi -> endpoint) -> MkLink endpoint Link
- allLinks' :: HasLink api => (Link -> a) -> Proxy api -> MkLink api a
- allLinks :: HasLink api => Proxy api -> MkLink api Link
- safeLink' :: (IsElem endpoint api, HasLink endpoint) => (Link -> a) -> Proxy api -> Proxy endpoint -> MkLink endpoint a
- safeLink :: (IsElem endpoint api, HasLink endpoint) => Proxy api -> Proxy endpoint -> MkLink endpoint Link
- linkURI' :: LinkArrayElementStyle -> Link -> URI
- linkURI :: Link -> URI
- linkQueryParams :: Link -> [Param]
- linkSegments :: Link -> [String]
- data Link
- data Param
- data LinkArrayElementStyle
- data AsLink a
- class HasLink (endpoint :: k) where
- data WithNamedContext (name :: Symbol) (subContext :: [*]) subApi
- type family Endpoints api :: [*] where ...
- type family IsElem' a s :: Constraint
- type family IsElem endpoint api :: Constraint where ...
- type family IsSubAPI sub api :: Constraint where ...
- type family AllIsElem (xs :: [*]) api :: Constraint where ...
- type family IsIn endpoint api :: Constraint where ...
- type family IsStrictSubAPI sub api :: Constraint where ...
- type family AllIsIn (xs :: [*]) api :: Constraint where ...
- type family MapSub (e :: k) (xs :: [*]) :: [*] where ...
- type family AppendList (xs :: [a]) (ys :: [a]) :: [a] where ...
- type family IsSubList (a :: [t]) (b :: [t]) :: Constraint where ...
- type Elem (e :: t) (es :: [t]) = ElemGo e es es
- type family ElemGo (e :: t) (es :: [t]) (orig :: t1) :: Constraint where ...
- data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) a :: forall k1. k1 -> Nat -> [*] -> * -> *
- type Get = Verb GET 200
- type Post = Verb POST 200
- type Put = Verb PUT 200
- type Delete = Verb DELETE 200
- type Patch = Verb PATCH 200
- type PostCreated = Verb POST 201
- type GetAccepted = Verb GET 202
- type PostAccepted = Verb POST 202
- type DeleteAccepted = Verb DELETE 202
- type PatchAccepted = Verb PATCH 202
- type PutAccepted = Verb PUT 202
- type GetNonAuthoritative = Verb GET 203
- type PostNonAuthoritative = Verb POST 203
- type DeleteNonAuthoritative = Verb DELETE 203
- type PatchNonAuthoritative = Verb PATCH 203
- type PutNonAuthoritative = Verb PUT 203
- type GetNoContent = Verb GET 204
- type PostNoContent = Verb POST 204
- type DeleteNoContent = Verb DELETE 204
- type PatchNoContent = Verb PATCH 204
- type PutNoContent = Verb PUT 204
- type GetResetContent = Verb GET 205
- type PostResetContent = Verb POST 205
- type GetPartialContent = Verb GET 206
- class ReflectMethod (a :: k) where
- data (path :: k) :> a :: forall k. k -> * -> *
- data Stream (method :: k1) (status :: Nat) framing contentType a :: forall k1. k1 -> Nat -> * -> * -> * -> *
- type StreamGet = Stream GET 200
- type StreamPost = Stream POST 200
- newtype StreamGenerator a = StreamGenerator {
- getStreamGenerator :: (a -> IO ()) -> (a -> IO ()) -> IO ()
- class ToStreamGenerator a b | a -> b where
- newtype ResultStream a = ResultStream (forall b. (IO (Maybe (Either String a)) -> IO b) -> IO b)
- class BuildFromStream a b where
- class FramingRender (strategy :: k) (a :: k1) where
- data BoundaryStrategy
- data ByteStringParser a = ByteStringParser {
- parseIncremental :: ByteString -> Maybe (a, ByteString)
- parseEOF :: ByteString -> (a, ByteString)
- class FramingUnrender (strategy :: k) (a :: k1) where
- data NoFraming
- data NewlineFraming
- data NetstringFraming
- noHeader :: AddHeader h v orig new => orig -> new
- addHeader :: AddHeader h v orig new => v -> orig -> new
- data Headers (ls :: [*]) a = Headers {
- getResponse :: a
- getHeadersHList :: HList ls
- data ResponseHeader (sym :: Symbol) a
- data HList (a :: [*]) where
- class BuildHeadersTo (hs :: [*]) where
- class GetHeaders ls where
- class AddHeader (h :: Symbol) v orig new | h v orig -> new, new -> h, new -> v, new -> orig
- type ReqBody = ReqBody' (Required ': (Strict ': ([] :: [*])))
- data ReqBody' (mods :: [*]) (contentTypes :: [*]) a
- data RemoteHost
- data Raw
- type QueryParam = QueryParam' (Optional ': (Strict ': ([] :: [*])))
- data QueryParam' (mods :: [*]) (sym :: Symbol) a
- data QueryParams (sym :: Symbol) a
- data QueryFlag (sym :: Symbol)
- type Header = (Header' (Optional ': (Strict ': ([] :: [*]))) :: Symbol -> k -> *)
- data Header' (mods :: [*]) (sym :: Symbol) (a :: k) :: forall k. [*] -> Symbol -> k -> *
- data Required
- data Optional
- data Lenient
- data Strict
- data IsSecure
- data AuthProtect (tag :: k) :: forall k. k -> *
- data EmptyAPI = EmptyAPI
- data Summary (sym :: Symbol)
- data Description (sym :: Symbol)
- data JSON
- data PlainText
- data FormUrlEncoded
- data OctetStream
- class Accept (ctype :: k) where
- class Accept ctype => MimeRender (ctype :: k) a where
- class Accept ctype => MimeUnrender (ctype :: k) a where
- data NoContent = NoContent
- type Capture = Capture' ([] :: [*])
- data Capture' (mods :: [*]) (sym :: Symbol) a
- data CaptureAll (sym :: Symbol) a
- data BasicAuth (realm :: Symbol) userData
- data BasicAuthData = BasicAuthData {}
- data a :<|> b = a :<|> b
- type Vault = Vault RealWorld
- class SBoolI (b :: Bool) where
- data SBool (b :: Bool) where
- serveDirectory :: FilePath -> ServerT Raw m
- serveDirectoryWith :: StaticSettings -> ServerT Raw m
- serveDirectoryEmbedded :: [(FilePath, ByteString)] -> ServerT Raw m
- serveDirectoryWebAppLookup :: ETagLookup -> FilePath -> ServerT Raw m
- serveDirectoryFileServer :: FilePath -> ServerT Raw m
- serveDirectoryWebApp :: FilePath -> ServerT Raw m
- layoutWithContext :: HasServer api context => Proxy api -> Context context -> Text
- layout :: HasServer api ([] :: [*]) => Proxy api -> Text
- hoistServer :: HasServer api ([] :: [*]) => Proxy api -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n
- serveWithContext :: HasServer api context => Proxy api -> Context context -> Server api -> Application
- serve :: HasServer api ([] :: [*]) => Proxy api -> Server api -> Application
- emptyServer :: ServerT EmptyAPI m
- class HasServer (api :: k) (context :: [*]) where
- type Server (api :: k) = ServerT api Handler
- data EmptyServer
- data BasicAuthResult usr
- = Unauthorized
- | BadPassword
- | NoSuchUser
- | Authorized usr
- newtype BasicAuthCheck usr = BasicAuthCheck {
- unBasicAuthCheck :: BasicAuthData -> IO (BasicAuthResult usr)
- tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router env -> Router env
- toApplication :: RoutingApplication -> Application
- runHandler :: Handler a -> IO (Either ServantErr a)
- runHandler' :: Handler a -> ExceptT ServantErr IO a
- err505 :: ServantErr
- err504 :: ServantErr
- err503 :: ServantErr
- err502 :: ServantErr
- err501 :: ServantErr
- err500 :: ServantErr
- err422 :: ServantErr
- err418 :: ServantErr
- err417 :: ServantErr
- err416 :: ServantErr
- err415 :: ServantErr
- err414 :: ServantErr
- err413 :: ServantErr
- err412 :: ServantErr
- err411 :: ServantErr
- err410 :: ServantErr
- err409 :: ServantErr
- err407 :: ServantErr
- err406 :: ServantErr
- err405 :: ServantErr
- err404 :: ServantErr
- err403 :: ServantErr
- err402 :: ServantErr
- err401 :: ServantErr
- err400 :: ServantErr
- err307 :: ServantErr
- err305 :: ServantErr
- err304 :: ServantErr
- err303 :: ServantErr
- err302 :: ServantErr
- err301 :: ServantErr
- err300 :: ServantErr
- data ServantErr = ServantErr {
- errHTTPCode :: Int
- errReasonPhrase :: String
- errBody :: ByteString
- errHeaders :: [Header]
- descendIntoNamedContext :: HasContextEntry context (NamedContext name subContext) => Proxy name -> Context context -> Context subContext
- data Context (contextTypes :: [*]) where
- EmptyContext :: Context ([] :: [*])
- (:.) :: Context (x ': xs)
- class HasContextEntry (context :: [*]) val where
- data NamedContext (name :: Symbol) (subContext :: [*]) = NamedContext (Context subContext)
- type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
- newtype Tagged (s :: k) b :: forall k. k -> * -> * = Tagged {
- unTagged :: b
- splitOn :: Eq a => [a] -> [a] -> [[a]]
- fromLT :: ConvertibleStrings LT a => LT -> a
- fromLazyText :: ConvertibleStrings LazyText a => LazyText -> a
- fromST :: ConvertibleStrings ST a => ST -> a
- fromStrictText :: ConvertibleStrings StrictText a => StrictText -> a
- fromLBS :: ConvertibleStrings LBS a => LBS -> a
- fromLazyByteString :: ConvertibleStrings LazyByteString a => LazyByteString -> a
- fromSBS :: ConvertibleStrings SBS a => SBS -> a
- fromStrictByteString :: ConvertibleStrings StrictByteString a => StrictByteString -> a
- toLT :: ConvertibleStrings a LT => a -> LT
- toLazyText :: ConvertibleStrings a LazyText => a -> LazyText
- toST :: ConvertibleStrings a ST => a -> ST
- toStrictText :: ConvertibleStrings a StrictText => a -> StrictText
- toLBS :: ConvertibleStrings a LBS => a -> LBS
- toLazyByteString :: ConvertibleStrings a LazyByteString => a -> LazyByteString
- toSBS :: ConvertibleStrings a SBS => a -> SBS
- toStrictByteString :: ConvertibleStrings a StrictByteString => a -> StrictByteString
- toString :: ConvertibleStrings a String => a -> String
- cs :: ConvertibleStrings a b => a -> b
- class ConvertibleStrings a b where
- type StrictByteString = ByteString
- type SBS = ByteString
- type LazyByteString = ByteString
- type LBS = ByteString
- type StrictText = Text
- type ST = Text
- type LazyText = Text
- type LT = Text
- exceptToMaybeT :: Functor m => ExceptT e m a -> MaybeT m a
- maybeToExceptT :: Functor m => e -> MaybeT m a -> ExceptT e m a
- mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId)
- runInUnboundThread :: MonadUnliftIO m => m a -> m a
- runInBoundThread :: MonadUnliftIO m => m a -> m a
- forkOS :: MonadUnliftIO m => m () -> m ThreadId
- yield :: MonadIO m => m ()
- threadCapability :: MonadIO m => ThreadId -> m (Int, Bool)
- setNumCapabilities :: MonadIO m => Int -> m ()
- getNumCapabilities :: MonadIO m => m Int
- forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId
- forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId
- killThread :: MonadIO m => ThreadId -> m ()
- forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId
- forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId
- forkIO :: MonadUnliftIO m => m () -> m ThreadId
- type Middleware = Application -> Application
- defWaiMain :: Application -> IO ()
- defPutListening :: WaiOptions -> IO ()
- waiMain :: (WaiOptions -> IO ()) -> (WaiOptions -> IO ()) -> Application -> IO ()
- runGraceful :: GracefulMode -> (Settings -> Application -> IO ()) -> Settings -> Application -> IO ()
- runActivated :: (Settings -> Socket -> Application -> IO ()) -> Settings -> Application -> IO ()
- data GracefulMode
- data WaiOptions = WaiOptions Int String String String String String (Maybe Bool)
- metrics :: WaiMetrics -> Middleware
- registerNamedWaiMetrics :: Text -> Store -> IO WaiMetrics
- registerWaiMetrics :: Store -> IO WaiMetrics
- data WaiMetrics = WaiMetrics {}
- runMagicbaneHandler :: β -> RIO β α -> Handler α
- magicbaneApp :: forall β χ ψ. HasServer χ ψ => Proxy χ -> Context ψ -> β -> ServerT χ (RIO β) -> Application
- type Formatter = TimedFastLogger -> CallStack -> LogSource -> LogLevel -> Utf8Builder -> IO ()
- type ModLogger = LogFunc
- newLogger :: LogType -> Formatter -> IO (TimedFastLogger, ModLogger)
- simpleFormatter :: Formatter
- newtype ModMetrics = ModMetrics Metrics
- forkMetricsServer :: ByteString -> Int -> IO Server
- newMetricsWith :: Store -> IO ModMetrics
- type WithLink α = Headers '[Header "Link" [HTTPLink]] α
- type HTTPLink = Link
- type Form = ReqBody '[FormUrlEncoded] [(Text, Text)]
- type Host = Header "Host" Text
- hPutStrLn :: MonadIO μ => Handle -> String -> μ ()
- mergeVal :: Value -> Value -> Value
- writeForm :: (ConvertibleStrings α Text, ConvertibleStrings β Text, ConvertibleStrings ByteString γ) => [(α, β)] -> γ
- readForm :: (ConvertibleStrings Text α, ConvertibleStrings Text β, ConvertibleStrings γ ByteString) => γ -> Maybe [(α, β)]
- formList :: Form -> [(Text, Text)]
- formToObject :: [(Text, Text)] -> Value
- formKey :: Parser [Text]
- parseUri :: ConvertibleStrings α String => α -> URI
- slugify :: Text -> Text
- errText :: ServantErr -> ByteString -> ServantErr
- throwErrText :: MonadThrow μ => ServantErr -> ByteString -> μ α
- type MonadHTTP ψ μ = (HasHttpManager ψ, MonadReader ψ μ, MonadUnliftIO μ)
- newtype ModHttpClient = ModHttpClient Manager
- newHttpClient :: IO ModHttpClient
- runHTTP :: ExceptT ε μ α -> μ (Either ε α)
- reqU :: MonadHTTP ψ μ => URI -> ExceptT Text μ Request
- reqS :: (MonadHTTP ψ μ, ConvertibleStrings σ String) => σ -> ExceptT Text μ Request
- anyStatus :: MonadHTTP ψ μ => Request -> ExceptT Text μ Request
- postForm :: MonadHTTP ψ μ => [(Text, Text)] -> Request -> ExceptT Text μ Request
- postJson :: (MonadHTTP ψ μ, ToJSON α) => α -> Request -> ExceptT Text μ Request
- performWithFn :: (MonadHTTP ψ μ, MonadCatch μ) => (ConduitM ι ByteString μ () -> ConduitT () Void μ ρ) -> Request -> ExceptT Text μ (Response ρ)
- performWithVoid :: (MonadHTTP ψ μ, MonadCatch μ) => Request -> ExceptT Text μ (Response ())
- performWithBytes :: (MonadHTTP ψ μ, MonadCatch μ) => Request -> ExceptT Text μ (Response ByteString)
- applyHeaders :: RequestHeaders -> Request -> Request
- removeHeaders :: [HeaderName] -> Request -> Request
- askObj :: (Has β α, MonadReader α μ) => μ β
- askOpt :: (Has β α, MonadReader α μ) => (β -> ψ) -> μ ψ
- decodeEnvy :: FromEnv a => IO (Maybe a)
- withEnvConfig :: FromEnv α => (α -> IO ()) -> IO ()
- type BasicApp α = RIO BasicContext α
- type BasicContext = (ModHttpClient, ModLogger)
- newBasicContext :: IO BasicContext
Documentation
If the first argument evaluates to True
, then the result is the
second argument. Otherwise an AssertionFailed
exception is raised,
containing a String
with the source file and line number of the
call to assert
.
Assertions can normally be turned on or off with a compiler flag
(for GHC, assertions are normally on unless optimisation is turned on
with -O
or the -fignore-asserts
option is given). When assertions are turned off, the first
argument to assert
is ignored, and the second argument is
returned as the result.
The class Typeable
allows a concrete representation of a type to
be calculated.
typeRep#
eitherDecodeFileStrict' :: FromJSON a => FilePath -> IO (Either String a) #
Like decodeFileStrict'
but returns an error message when decoding fails.
eitherDecodeStrict' :: FromJSON a => ByteString -> Either String a #
Like decodeStrict'
but returns an error message when decoding fails.
eitherDecode' :: FromJSON a => ByteString -> Either String a #
Like decode'
but returns an error message when decoding fails.
eitherDecodeFileStrict :: FromJSON a => FilePath -> IO (Either String a) #
Like decodeFileStrict
but returns an error message when decoding fails.
eitherDecodeStrict :: FromJSON a => ByteString -> Either String a #
Like decodeStrict
but returns an error message when decoding fails.
eitherDecode :: FromJSON a => ByteString -> Either String a #
Like decode
but returns an error message when decoding fails.
decodeFileStrict' :: FromJSON a => FilePath -> IO (Maybe a) #
Efficiently deserialize a JSON value from a file.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input file's content must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses and performs conversion immediately. See
json'
for details.
decodeStrict' :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a strict ByteString
.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses and performs conversion immediately. See
json'
for details.
decode' :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a lazy ByteString
.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses and performs conversion immediately. See
json'
for details.
decodeFileStrict :: FromJSON a => FilePath -> IO (Maybe a) #
Efficiently deserialize a JSON value from a file.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input file's content must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses immediately, but defers conversion. See
json
for details.
decodeStrict :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a strict ByteString
.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses immediately, but defers conversion. See
json
for details.
decode :: FromJSON a => ByteString -> Maybe a #
Efficiently deserialize a JSON value from a lazy ByteString
.
If this fails due to incomplete or invalid input, Nothing
is
returned.
The input must consist solely of a JSON document, with no trailing data except for whitespace.
This function parses immediately, but defers conversion. See
json
for details.
encodeFile :: ToJSON a => FilePath -> a -> IO () #
Efficiently serialize a JSON value as a lazy ByteString
and write it to a file.
encode :: ToJSON a => a -> ByteString #
Efficiently serialize a JSON value as a lazy ByteString
.
This is implemented in terms of the ToJSON
class's toEncoding
method.
type GToEncoding = GToJSON Encoding #
toEncoding2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Encoding #
Lift the standard toEncoding
function through the type constructor.
toJSON2 :: (ToJSON2 f, ToJSON a, ToJSON b) => f a b -> Value #
Lift the standard toJSON
function through the type constructor.
toEncoding1 :: (ToJSON1 f, ToJSON a) => f a -> Encoding #
Lift the standard toEncoding
function through the type constructor.
toJSON1 :: (ToJSON1 f, ToJSON a) => f a -> Value #
Lift the standard toJSON
function through the type constructor.
genericLiftToEncoding :: (Generic1 f, GToJSON Encoding One (Rep1 f)) => Options -> (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding #
A configurable generic JSON encoder. This function applied to
defaultOptions
is used as the default for liftToEncoding
when the type
is an instance of Generic1
.
genericToEncoding :: (Generic a, GToJSON Encoding Zero (Rep a)) => Options -> a -> Encoding #
A configurable generic JSON encoder. This function applied to
defaultOptions
is used as the default for toEncoding
when the type
is an instance of Generic
.
genericLiftToJSON :: (Generic1 f, GToJSON Value One (Rep1 f)) => Options -> (a -> Value) -> ([a] -> Value) -> f a -> Value #
A configurable generic JSON creator. This function applied to
defaultOptions
is used as the default for liftToJSON
when the type
is an instance of Generic1
.
genericToJSON :: (Generic a, GToJSON Value Zero (Rep a)) => Options -> a -> Value #
A configurable generic JSON creator. This function applied to
defaultOptions
is used as the default for toJSON
when the type
is an instance of Generic
.
A type that can be converted to JSON.
Instances in general must specify toJSON
and should (but don't need
to) specify toEncoding
.
An example type and instance:
-- Allow ourselves to writeText
literals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceToJSON
Coord wheretoJSON
(Coord x y) =object
["x".=
x, "y".=
y]toEncoding
(Coord x y) =pairs
("x".=
x<>
"y".=
y)
Instead of manually writing your ToJSON
instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
toJSON
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic
ToJSON
instance. If you require nothing other than
defaultOptions
, it is sufficient to write (and this is the only
alternative where the default toJSON
implementation is sufficient):
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Coord = Coord { x :: Double, y :: Double } derivingGeneric
instanceToJSON
Coord wheretoEncoding
=genericToEncoding
defaultOptions
If on the other hand you wish to customize the generic decoding, you have to implement both methods:
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceToJSON
Coord wheretoJSON
=genericToJSON
customOptionstoEncoding
=genericToEncoding
customOptions
Previous versions of this library only had the toJSON
method. Adding
toEncoding
had to reasons:
- toEncoding is more efficient for the common case that the output of
toJSON
is directly serialized to aByteString
. Further, expressing either method in terms of the other would be non-optimal. - The choice of defaults allows a smooth transition for existing users:
Existing instances that do not define
toEncoding
still compile and have the correct semantics. This is ensured by making the default implementation oftoEncoding
usetoJSON
. This produces correct results, but since it performs an intermediate conversion to aValue
, it will be less efficient than directly emitting anEncoding
. (this also means that specifying nothing more thaninstance ToJSON Coord
would be sufficient as a generically decoding instance, but there probably exists no good reason to not specifytoEncoding
in new instances.)
Convert a Haskell value to a JSON-friendly intermediate type.
toEncoding :: a -> Encoding #
Encode a Haskell value as JSON.
The default implementation of this method creates an
intermediate Value
using toJSON
. This provides
source-level compatibility for people upgrading from older
versions of this library, but obviously offers no performance
advantage.
To benefit from direct encoding, you must provide an
implementation for this method. The easiest way to do so is by
having your types implement Generic
using the DeriveGeneric
extension, and then have GHC generate a method body as follows.
instanceToJSON
Coord wheretoEncoding
=genericToEncoding
defaultOptions
toJSONList :: [a] -> Value #
toEncodingList :: [a] -> Encoding #
Instances
A key-value pair for encoding a JSON object.
Typeclass for types that can be used as the key of a map-like container
(like Map
or HashMap
). For example, since Text
has a ToJSONKey
instance and Char
has a ToJSON
instance, we can encode a value of
type Map
Text
Char
:
>>>
LBC8.putStrLn $ encode $ Map.fromList [("foo" :: Text, 'a')]
{"foo":"a"}
Since Int
also has a ToJSONKey
instance, we can similarly write:
>>>
LBC8.putStrLn $ encode $ Map.fromList [(5 :: Int, 'a')]
{"5":"a"}
JSON documents only accept strings as object keys. For any type
from base
that has a natural textual representation, it can be
expected that its ToJSONKey
instance will choose that representation.
For data types that lack a natural textual representation, an alternative is provided. The map-like container is represented as a JSON array instead of a JSON object. Each value in the array is an array with exactly two values. The first is the key and the second is the value.
For example, values of type '[Text]' cannot be encoded to a
string, so a Map
with keys of type '[Text]' is encoded as follows:
>>>
LBC8.putStrLn $ encode $ Map.fromList [(["foo","bar","baz" :: Text], 'a')]
[[["foo","bar","baz"],"a"]]
The default implementation of ToJSONKey
chooses this method of
encoding a key, using the ToJSON
instance of the type.
To use your own data type as the key in a map, all that is needed
is to write a ToJSONKey
(and possibly a FromJSONKey
) instance
for it. If the type cannot be trivially converted to and from Text
,
it is recommended that ToJSONKeyValue
is used. Since the default
implementations of the typeclass methods can build this from a
ToJSON
instance, there is nothing that needs to be written:
data Foo = Foo { fooAge :: Int, fooName :: Text } deriving (Eq,Ord,Generic) instance ToJSON Foo instance ToJSONKey Foo
That's it. We can now write:
>>>
let m = Map.fromList [(Foo 4 "bar",'a'),(Foo 6 "arg",'b')]
>>>
LBC8.putStrLn $ encode m
[[{"fooName":"bar","fooAge":4},"a"],[{"fooName":"arg","fooAge":6},"b"]]
The next case to consider is if we have a type that is a
newtype wrapper around Text
. The recommended approach is to use
generalized newtype deriving:
newtype RecordId = RecordId { getRecordId :: Text} deriving (Eq,Ord,ToJSONKey)
Then we may write:
>>>
LBC8.putStrLn $ encode $ Map.fromList [(RecordId "abc",'a')]
{"abc":"a"}
Simple sum types are a final case worth considering. Suppose we have:
data Color = Red | Green | Blue deriving (Show,Read,Eq,Ord)
It is possible to get the ToJSONKey
instance for free as we did
with Foo
. However, in this case, we have a natural way to go to
and from Text
that does not require any escape sequences. So, in
this example, ToJSONKeyText
will be used instead of ToJSONKeyValue
.
The Show
instance can be used to help write ToJSONKey
:
instance ToJSONKey Color where toJSONKey = ToJSONKeyText f g where f = Text.pack . show g = text . Text.pack . show -- text function is from Data.Aeson.Encoding
The situation of needing to turning function a -> Text
into
a ToJSONKeyFunction
is common enough that a special combinator
is provided for it. The above instance can be rewritten as:
instance ToJSONKey Color where toJSONKey = toJSONKeyText (Text.pack . show)
The performance of the above instance can be improved by
not using String
as an intermediate step when converting to
Text
. One option for improving performance would be to use
template haskell machinery from the text-show
package. However,
even with the approach, the Encoding
(a wrapper around a bytestring
builder) is generated by encoding the Text
to a ByteString
,
an intermediate step that could be avoided. The fastest possible
implementation would be:
-- Assuming that OverloadedStrings is enabled instance ToJSONKey Color where toJSONKey = ToJSONKeyText f g where f x = case x of {Red -> "Red";Green ->"Green";Blue -> "Blue"} g x = case x of {Red -> text "Red";Green -> text "Green";Blue -> text "Blue"} -- text function is from Data.Aeson.Encoding
This works because GHC can lift the encoded values out of the case statements, which means that they are only evaluated once. This approach should only be used when there is a serious need to maximize performance.
toJSONKey :: ToJSONKeyFunction a #
Strategy for rendering the key for a map-like container.
toJSONKeyList :: ToJSONKeyFunction [a] #
Instances
data ToJSONKeyFunction a #
ToJSONKeyText !(a -> Text) !(a -> Encoding' Text) | key is encoded to string, produces object |
ToJSONKeyValue !(a -> Value) !(a -> Encoding) | key is encoded to value, produces array |
class ToJSON1 (f :: * -> *) where #
Lifting of the ToJSON
class to unary type constructors.
Instead of manually writing your ToJSON1
instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
toJSON1
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic1
ToJSON1
instance for your datatype without giving
definitions for liftToJSON
or liftToEncoding
.
For example:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Pair = Pair { pairFst :: a, pairSnd :: b } derivingGeneric1
instanceToJSON
a =>ToJSON1
(Pair a)
If the default implementation doesn't give exactly the results you want,
you can customize the generic encoding with only a tiny amount of
effort, using genericLiftToJSON
and genericLiftToEncoding
with
your preferred Options
:
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceToJSON
a =>ToJSON1
(Pair a) whereliftToJSON
=genericLiftToJSON
customOptionsliftToEncoding
=genericLiftToEncoding
customOptions
See also ToJSON
.
liftToJSON :: (a -> Value) -> ([a] -> Value) -> f a -> Value #
liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [f a] -> Value #
liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> f a -> Encoding #
liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [f a] -> Encoding #
Instances
ToJSON1 [] | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> [a] -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [[a]] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> [a] -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [[a]] -> Encoding # | |
ToJSON1 Maybe | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Maybe a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Maybe a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Maybe a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Maybe a] -> Encoding # | |
ToJSON1 Min | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Max | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 First | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> First a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [First a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> First a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [First a] -> Encoding # | |
ToJSON1 Last | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 WrappedMonoid | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> WrappedMonoid a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [WrappedMonoid a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> WrappedMonoid a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [WrappedMonoid a] -> Encoding # | |
ToJSON1 Option | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Option a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Option a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Option a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Option a] -> Encoding # | |
ToJSON1 Identity | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Identity a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Identity a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Identity a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Identity a] -> Encoding # | |
ToJSON1 First | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> First a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [First a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> First a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [First a] -> Encoding # | |
ToJSON1 Last | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Dual | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 NonEmpty | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> NonEmpty a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [NonEmpty a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> NonEmpty a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [NonEmpty a] -> Encoding # | |
ToJSON1 IntMap | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> IntMap a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [IntMap a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> IntMap a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [IntMap a] -> Encoding # | |
ToJSON1 Tree | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Seq | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 Set | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSON1 DList | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> DList a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [DList a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> DList a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [DList a] -> Encoding # | |
ToJSON1 Vector | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Vector a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Vector a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Vector a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Vector a] -> Encoding # | |
ToJSON1 HashSet | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashSet a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashSet a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashSet a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashSet a] -> Encoding # | |
ToJSON a => ToJSON1 (Either a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Either a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Either a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Either a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Either a a0] -> Encoding # | |
ToJSON a => ToJSON1 ((,) a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, a0)] -> Encoding # | |
ToJSONKey k => ToJSON1 (HashMap k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> HashMap k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [HashMap k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> HashMap k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [HashMap k a] -> Encoding # | |
ToJSONKey k => ToJSON1 (Map k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Map k a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Map k a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Map k a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Map k a] -> Encoding # | |
ToJSON1 (Proxy :: * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
ToJSON a => ToJSON1 (These a) | |
Defined in Data.These liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> These a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [These a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> These a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [These a a0] -> Encoding # | |
(ToJSON a, ToJSON b) => ToJSON1 ((,,) a b) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, a0)] -> Encoding # | |
ToJSON a => ToJSON1 (Const a :: * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Const a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Const a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Const a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Const a a0] -> Encoding # | |
ToJSON1 (Tagged a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Tagged a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Tagged a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Tagged a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Tagged a a0] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON1 ((,,,) a b c) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, a0)] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (Product f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Product f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Product f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Product f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Product f g a] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (Sum f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Sum f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Sum f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Sum f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Sum f g a] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON1 ((,,,,) a b c d) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, a0)] -> Encoding # | |
(ToJSON1 f, ToJSON1 g) => ToJSON1 (Compose f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Compose f g a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Compose f g a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Compose f g a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Compose f g a] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON1 ((,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON1 ((,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON1 ((,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON1 ((,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON1 ((,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON1 ((,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON1 ((,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON1 ((,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON1 ((,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON1 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m n) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0)] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0) -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, a0)] -> Encoding # |
class ToJSON2 (f :: * -> * -> *) where #
Lifting of the ToJSON
class to binary type constructors.
Instead of manually writing your ToJSON2
instance, Data.Aeson.TH
provides Template Haskell functions which will derive an instance at compile time.
The compiler cannot provide a default generic implementation for liftToJSON2
,
unlike toJSON
and liftToJSON
.
liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> f a b -> Value #
liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [f a b] -> Value #
liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> f a b -> Encoding #
liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [f a b] -> Encoding #
Instances
ToJSON2 Either | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Either a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Either a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Either a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Either a b] -> Encoding # | |
ToJSON2 (,) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> (a, b) -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [(a, b)] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> (a, b) -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [(a, b)] -> Encoding # | |
ToJSON2 These | |
Defined in Data.These liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> These a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [These a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> These a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [These a b] -> Encoding # | |
ToJSON a => ToJSON2 ((,,) a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b -> Value) -> ([b] -> Value) -> (a, a0, b) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b -> Value) -> ([b] -> Value) -> [(a, a0, b)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> (a, a0, b) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [(a, a0, b)] -> Encoding # | |
ToJSON2 (Const :: * -> * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Const a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Const a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Const a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Const a b] -> Encoding # | |
ToJSON2 (Tagged :: * -> * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Tagged a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Tagged a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Tagged a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Tagged a b] -> Encoding # | |
(ToJSON a, ToJSON b) => ToJSON2 ((,,,) a b) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c) => ToJSON2 ((,,,,) a b c) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON2 ((,,,,,) a b c d) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON2 ((,,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON2 ((,,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON2 ((,,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON2 ((,,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON2 ((,,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, a0, b0)] -> Encoding # | |
(ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0) -> Value # liftToJSONList2 :: (a0 -> Value) -> ([a0] -> Value) -> (b0 -> Value) -> ([b0] -> Value) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0)] -> Value # liftToEncoding2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> (a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0) -> Encoding # liftToEncodingList2 :: (a0 -> Encoding) -> ([a0] -> Encoding) -> (b0 -> Encoding) -> ([b0] -> Encoding) -> [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0)] -> Encoding # |
fromEncoding :: Encoding' tag -> Builder #
Acquire the underlying bytestring builder.
A series of values that, when encoded, should be separated by
commas. Since 0.11.0.0, the .=
operator is overloaded to create
either (Text, Value)
or Series
. You can use Series when
encoding directly to a bytestring builder as in the following
example:
toEncoding (Person name age) = pairs ("name" .= name <> "age" .= age)
(.!=) :: Parser (Maybe a) -> a -> Parser a #
Helper for use in combination with .:?
to provide default
values for optional JSON object fields.
This combinator is most useful if the key and value can be absent
from an object without affecting its validity and we know a default
value to assign in that case. If the key and value are mandatory,
use .:
instead.
Example usage:
v1 <- o.:?
"opt_field_with_dfl" .!= "default_val" v2 <- o.:
"mandatory_field" v3 <- o.:?
"opt_field2"
(.:?) :: FromJSON a => Object -> Text -> Parser (Maybe a) #
Retrieve the value associated with the given key of an Object
. The
result is Nothing
if the key is not present or if its value is Null
,
or empty
if the value cannot be converted to the desired type.
This accessor is most useful if the key and value can be absent
from an object without affecting its validity. If the key and
value are mandatory, use .:
instead.
(.:) :: FromJSON a => Object -> Text -> Parser a #
Retrieve the value associated with the given key of an Object
.
The result is empty
if the key is not present or the value cannot
be converted to the desired type.
This accessor is appropriate if the key and value must be present
in an object for it to be valid. If the key and value are
optional, use .:?
instead.
fromJSON :: FromJSON a => Value -> Result a #
Convert a value from JSON, failing if the types do not match.
withEmbeddedJSON :: String -> (Value -> Parser a) -> Value -> Parser a #
Decode a nested JSON-encoded string.
withBool :: String -> (Bool -> Parser a) -> Value -> Parser a #
applies withBool
expected f valuef
to the Bool
when value
is a
Bool
and fails using
otherwise.typeMismatch
expected
withScientific :: String -> (Scientific -> Parser a) -> Value -> Parser a #
applies withScientific
expected f valuef
to the Scientific
number
when value
is a Number
and fails using
otherwise.
.
Warning: If you are converting from a scientific to an unbounded
type such as typeMismatch
expectedInteger
you may want to add a restriction on the
size of the exponent (see withBoundedScientific
) to prevent
malicious input from filling up the memory of the target system.
withArray :: String -> (Array -> Parser a) -> Value -> Parser a #
applies withArray
expected f valuef
to the Array
when value
is
an Array
and fails using
otherwise.typeMismatch
expected
withText :: String -> (Text -> Parser a) -> Value -> Parser a #
applies withText
expected f valuef
to the Text
when value
is a
String
and fails using
otherwise.typeMismatch
expected
withObject :: String -> (Object -> Parser a) -> Value -> Parser a #
applies withObject
expected f valuef
to the Object
when value
is an Object
and fails using
otherwise.typeMismatch
expected
parseJSON2 :: (FromJSON2 f, FromJSON a, FromJSON b) => Value -> Parser (f a b) #
Lift the standard parseJSON
function through the type constructor.
parseJSON1 :: (FromJSON1 f, FromJSON a) => Value -> Parser (f a) #
Lift the standard parseJSON
function through the type constructor.
genericLiftParseJSON :: (Generic1 f, GFromJSON One (Rep1 f)) => Options -> (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a) #
A configurable generic JSON decoder. This function applied to
defaultOptions
is used as the default for liftParseJSON
when the
type is an instance of Generic1
.
genericParseJSON :: (Generic a, GFromJSON Zero (Rep a)) => Options -> Value -> Parser a #
A configurable generic JSON decoder. This function applied to
defaultOptions
is used as the default for parseJSON
when the
type is an instance of Generic
.
class GFromJSON arity (f :: * -> *) where #
Class of generic representation types that can be converted from JSON.
gParseJSON :: Options -> FromArgs arity a -> Value -> Parser (f a) #
This method (applied to defaultOptions
) is used as the
default generic implementation of parseJSON
(if the arity
is Zero
)
or liftParseJSON
(if the arity
is One
).
Instances
GFromJSON One Par1 | |
Defined in Data.Aeson.Types.FromJSON | |
GFromJSON arity (U1 :: * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
FromJSON1 f => GFromJSON One (Rec1 f) | |
Defined in Data.Aeson.Types.FromJSON | |
(ConsFromJSON arity a, AllNullary (C1 c a) allNullary, ParseSum arity (C1 c a) allNullary) => GFromJSON arity (D1 d (C1 c a)) | |
Defined in Data.Aeson.Types.FromJSON | |
ConsFromJSON arity a => GFromJSON arity (C1 c a) | |
Defined in Data.Aeson.Types.FromJSON | |
FromJSON a => GFromJSON arity (K1 i a :: * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
(AllNullary (a :+: b) allNullary, ParseSum arity (a :+: b) allNullary) => GFromJSON arity (a :+: b) | |
Defined in Data.Aeson.Types.FromJSON | |
(FromProduct arity a, FromProduct arity b, ProductSize a, ProductSize b) => GFromJSON arity (a :*: b) | |
Defined in Data.Aeson.Types.FromJSON | |
GFromJSON arity a => GFromJSON arity (M1 i c a) | |
Defined in Data.Aeson.Types.FromJSON | |
(FromJSON1 f, GFromJSON One g) => GFromJSON One (f :.: g) | |
Defined in Data.Aeson.Types.FromJSON |
A type that can be converted from JSON, with the possibility of failure.
In many cases, you can get the compiler to generate parsing code for you (see below). To begin, let's cover writing an instance by hand.
There are various reasons a conversion could fail. For example, an
Object
could be missing a required key, an Array
could be of
the wrong size, or a value could be of an incompatible type.
The basic ways to signal a failed conversion are as follows:
empty
andmzero
work, but are terse and uninformative;fail
yields a custom error message;typeMismatch
produces an informative message for cases when the value encountered is not of the expected type.
An example type and instance using typeMismatch
:
-- Allow ourselves to writeText
literals. {-# LANGUAGE OverloadedStrings #-} data Coord = Coord { x :: Double, y :: Double } instanceFromJSON
Coord whereparseJSON
(Object
v) = Coord<$>
v.:
"x"<*>
v.:
"y" -- We do not expect a non-Object
value here. -- We could usemzero
to fail, buttypeMismatch
-- gives a much more informative error message.parseJSON
invalid =typeMismatch
"Coord" invalid
For this common case of only being concerned with a single
type of JSON value, the functions withObject
, withNumber
, etc.
are provided. Their use is to be preferred when possible, since
they are more terse. Using withObject
, we can rewrite the above instance
(assuming the same language extension and data type) as:
instanceFromJSON
Coord whereparseJSON
=withObject
"Coord" $ \v -> Coord<$>
v.:
"x"<*>
v.:
"y"
Instead of manually writing your FromJSON
instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
parseJSON
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic
FromJSON
instance for your datatype without giving
a definition for parseJSON
.
For example, the previous example can be simplified to just:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Coord = Coord { x :: Double, y :: Double } derivingGeneric
instanceFromJSON
Coord
The default implementation will be equivalent to
parseJSON =
; If you need different
options, you can customize the generic decoding by defining:genericParseJSON
defaultOptions
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceFromJSON
Coord whereparseJSON
=genericParseJSON
customOptions
Instances
class FromJSONKey a where #
Read the docs for ToJSONKey
first. This class is a conversion
in the opposite direction. If you have a newtype wrapper around Text
,
the recommended way to define instances is with generalized newtype deriving:
newtype SomeId = SomeId { getSomeId :: Text } deriving (Eq,Ord,Hashable,FromJSONKey)
fromJSONKey :: FromJSONKeyFunction a #
Strategy for parsing the key of a map-like container.
fromJSONKeyList :: FromJSONKeyFunction [a] #
Instances
data FromJSONKeyFunction a #
This type is related to ToJSONKeyFunction
. If FromJSONKeyValue
is used in the
FromJSONKey
instance, then ToJSONKeyValue
should be used in the ToJSONKey
instance. The other three data constructors for this type all correspond to
ToJSONKeyText
. Strictly speaking, FromJSONKeyTextParser
is more powerful than
FromJSONKeyText
, which is in turn more powerful than FromJSONKeyCoerce
.
For performance reasons, these exist as three options instead of one.
FromJSONKeyCoerce !(CoerceText a) | uses |
FromJSONKeyText !(Text -> a) | conversion from |
FromJSONKeyTextParser !(Text -> Parser a) | conversion from |
FromJSONKeyValue !(Value -> Parser a) | conversion for non-textual keys |
Instances
Functor FromJSONKeyFunction | Only law abiding up to interpretation |
Defined in Data.Aeson.Types.FromJSON fmap :: (a -> b) -> FromJSONKeyFunction a -> FromJSONKeyFunction b # (<$) :: a -> FromJSONKeyFunction b -> FromJSONKeyFunction a # |
class FromJSON1 (f :: * -> *) where #
Lifting of the FromJSON
class to unary type constructors.
Instead of manually writing your FromJSON1
instance, there are two options
to do it automatically:
- Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so it will probably be more efficient than the following option.
- The compiler can provide a default generic implementation for
liftParseJSON
.
To use the second, simply add a deriving
clause to your
datatype and declare a Generic1
FromJSON1
instance for your datatype without giving
a definition for liftParseJSON
.
For example:
{-# LANGUAGE DeriveGeneric #-} import GHC.Generics data Pair a b = Pair { pairFst :: a, pairSnd :: b } derivingGeneric1
instanceFromJSON
a =>FromJSON1
(Pair a)
If the default implementation doesn't give exactly the results you want,
you can customize the generic decoding with only a tiny amount of
effort, using genericLiftParseJSON
with your preferred Options
:
customOptions =defaultOptions
{fieldLabelModifier
=map
toUpper
} instanceFromJSON
a =>FromJSON1
(Pair a) whereliftParseJSON
=genericLiftParseJSON
customOptions
liftParseJSON :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser (f a) #
liftParseJSONList :: (Value -> Parser a) -> (Value -> Parser [a]) -> Value -> Parser [f a] #
Instances
class FromJSON2 (f :: * -> * -> *) where #
Lifting of the FromJSON
class to binary type constructors.
Instead of manually writing your FromJSON2
instance, Data.Aeson.TH
provides Template Haskell functions which will derive an instance at compile time.
liftParseJSON2 :: (Value -> Parser a) -> (Value -> Parser [a]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser (f a b) #
liftParseJSONList2 :: (Value -> Parser a) -> (Value -> Parser [a]) -> (Value -> Parser b) -> (Value -> Parser [b]) -> Value -> Parser [f a b] #
Instances
FromJSON2 Either | |
Defined in Data.Aeson.Types.FromJSON | |
FromJSON2 (,) | |
Defined in Data.Aeson.Types.FromJSON | |
FromJSON2 These | |
Defined in Data.These | |
FromJSON a => FromJSON2 ((,,) a) | |
Defined in Data.Aeson.Types.FromJSON | |
FromJSON2 (Const :: * -> * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
FromJSON2 (Tagged :: * -> * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
(FromJSON a, FromJSON b) => FromJSON2 ((,,,) a b) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c) => FromJSON2 ((,,,,) a b c) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON2 ((,,,,,) a b c d) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON2 ((,,,,,,) a b c d e) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON2 ((,,,,,,,) a b c d e f) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON2 ((,,,,,,,,) a b c d e f g) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON2 ((,,,,,,,,,) a b c d e f g h) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON2 ((,,,,,,,,,,) a b c d e f g h i) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON2 ((,,,,,,,,,,,) a b c d e f g h i j) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON2 ((,,,,,,,,,,,,) a b c d e f g h i j k) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l) => FromJSON2 ((,,,,,,,,,,,,,) a b c d e f g h i j k l) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, a0, b0)] # | |
(FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m) => FromJSON2 ((,,,,,,,,,,,,,,) a b c d e f g h i j k l m) | |
Defined in Data.Aeson.Types.FromJSON liftParseJSON2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0) # liftParseJSONList2 :: (Value -> Parser a0) -> (Value -> Parser [a0]) -> (Value -> Parser b0) -> (Value -> Parser [b0]) -> Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m, a0, b0)] # |
Parse a top-level JSON value.
This is a strict version of json
which avoids building up thunks
during parsing; it performs all conversions immediately. Prefer
this version if most of the JSON data needs to be accessed.
This function is an alias for value'
. In aeson 0.8 and earlier, it
parsed only object or array types, in conformance with the
now-obsolete RFC 4627.
Parse a top-level JSON value.
The conversion of a parsed value to a Haskell value is deferred until the Haskell value is needed. This may improve performance if only a subset of the results of conversions are needed, but at a cost in thunk allocation.
This function is an alias for value
. In aeson 0.8 and earlier, it
parsed only object or array types, in conformance with the
now-obsolete RFC 4627.
camelTo2 :: Char -> String -> String #
Better version of camelTo
. Example where it works better:
camelTo '_' 'CamelAPICase' == "camel_apicase" camelTo2 '_' 'CamelAPICase' == "camel_api_case"
defaultTaggedObject :: SumEncoding #
Default TaggedObject
SumEncoding
options:
defaultTaggedObject =TaggedObject
{tagFieldName
= "tag" ,contentsFieldName
= "contents" }
Default encoding Options
:
Options
{fieldLabelModifier
= id ,constructorTagModifier
= id ,allNullaryToStringTag
= True ,omitNothingFields
= False ,sumEncoding
=defaultTaggedObject
,unwrapUnaryRecords
= False ,tagSingleConstructors
= False }
The result of running a Parser
.
Instances
Monad Result | |
Functor Result | |
MonadFail Result | |
Defined in Data.Aeson.Types.Internal | |
Applicative Result | |
Foldable Result | |
Defined in Data.Aeson.Types.Internal fold :: Monoid m => Result m -> m # foldMap :: Monoid m => (a -> m) -> Result a -> m # foldr :: (a -> b -> b) -> b -> Result a -> b # foldr' :: (a -> b -> b) -> b -> Result a -> b # foldl :: (b -> a -> b) -> b -> Result a -> b # foldl' :: (b -> a -> b) -> b -> Result a -> b # foldr1 :: (a -> a -> a) -> Result a -> a # foldl1 :: (a -> a -> a) -> Result a -> a # elem :: Eq a => a -> Result a -> Bool # maximum :: Ord a => Result a -> a # minimum :: Ord a => Result a -> a # | |
Traversable Result | |
Alternative Result | |
MonadPlus Result | |
Eq a => Eq (Result a) | |
Show a => Show (Result a) | |
Semigroup (Result a) | |
Monoid (Result a) | |
NFData a => NFData (Result a) | |
Defined in Data.Aeson.Types.Internal |
A JSON value represented as a Haskell value.
Instances
Eq Value | |
Data Value | |
Defined in Data.Aeson.Types.Internal gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value # dataTypeOf :: Value -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Value) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) # gmapT :: (forall b. Data b => b -> b) -> Value -> Value # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r # gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # | |
Read Value | |
Show Value | |
IsString Value | |
Defined in Data.Aeson.Types.Internal fromString :: String -> Value # | |
Generic Value | |
Lift Value | |
Hashable Value | |
Defined in Data.Aeson.Types.Internal | |
ToJSON Value | |
Defined in Data.Aeson.Types.ToJSON | |
KeyValue Pair | |
FromJSON Value | |
NFData Value | |
Defined in Data.Aeson.Types.Internal | |
FromString Encoding | |
Defined in Data.Aeson.Types.ToJSON fromString :: String -> Encoding | |
FromString Value | |
Defined in Data.Aeson.Types.ToJSON fromString :: String -> Value | |
GToJSON Encoding arity (U1 :: * -> *) | |
GToJSON Value arity (U1 :: * -> *) | |
ToJSON1 f => GToJSON Encoding One (Rec1 f) | |
ToJSON1 f => GToJSON Value One (Rec1 f) | |
ToJSON a => GToJSON Encoding arity (K1 i a :: * -> *) | |
(EncodeProduct arity a, EncodeProduct arity b) => GToJSON Encoding arity (a :*: b) | |
ToJSON a => GToJSON Value arity (K1 i a :: * -> *) | |
(WriteProduct arity a, WriteProduct arity b, ProductSize a, ProductSize b) => GToJSON Value arity (a :*: b) | |
(ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One (f :.: g) | |
(ToJSON1 f, GToJSON Value One g) => GToJSON Value One (f :.: g) | |
FromPairs Value (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
v ~ Value => KeyValuePair v (DList Pair) | |
Defined in Data.Aeson.Types.ToJSON | |
(GToJSON Encoding arity a, ConsToJSON Encoding arity a, Constructor c) => SumToJSON' TwoElemArray Encoding arity (C1 c a) | |
Defined in Data.Aeson.Types.ToJSON | |
(GToJSON Value arity a, ConsToJSON Value arity a, Constructor c) => SumToJSON' TwoElemArray Value arity (C1 c a) | |
Defined in Data.Aeson.Types.ToJSON | |
type Rep Value | |
Defined in Data.Aeson.Types.Internal type Rep Value = D1 (MetaData "Value" "Data.Aeson.Types.Internal" "aeson-1.4.0.0-Gkl5i9Wd8LB2NBsYGFzlk7" False) ((C1 (MetaCons "Object" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Object)) :+: (C1 (MetaCons "Array" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Array)) :+: C1 (MetaCons "String" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Text)))) :+: (C1 (MetaCons "Number" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Scientific)) :+: (C1 (MetaCons "Bool" PrefixI False) (S1 (MetaSel (Nothing :: Maybe Symbol) NoSourceUnpackedness SourceStrict DecidedStrict) (Rec0 Bool)) :+: C1 (MetaCons "Null" PrefixI False) (U1 :: * -> *)))) |
newtype DotNetTime #
A newtype wrapper for UTCTime
that uses the same non-standard
serialization format as Microsoft .NET, whose
System.DateTime
type is by default serialized to JSON as in the following example:
/Date(1302547608878)/
The number represents milliseconds since the Unix epoch.
DotNetTime | |
|
Instances
Options that specify how to encode/decode your datatype to/from JSON.
Options can be set using record syntax on defaultOptions
with the fields
below.
data SumEncoding #
Specifies how to encode constructors of a sum datatype.
TaggedObject | A constructor will be encoded to an object with a field
|
UntaggedValue | Constructor names won't be encoded. Instead only the contents of the constructor will be encoded as if the type had a single constructor. JSON encodings have to be disjoint for decoding to work properly. When decoding, constructors are tried in the order of definition. If some encodings overlap, the first one defined will succeed. Note: Nullary constructors are encoded as strings (using
Note: Only the last error is kept when decoding, so in the case of malformed JSON, only an error for the last constructor will be reported. |
ObjectWithSingleField | A constructor will be encoded to an object with a single
field named after the constructor tag (modified by the
|
TwoElemArray | A constructor will be encoded to a 2-element array where the
first element is the tag of the constructor (modified by the
|
Instances
Eq SumEncoding | |
Defined in Data.Aeson.Types.Internal (==) :: SumEncoding -> SumEncoding -> Bool # (/=) :: SumEncoding -> SumEncoding -> Bool # | |
Show SumEncoding | |
Defined in Data.Aeson.Types.Internal showsPrec :: Int -> SumEncoding -> ShowS # show :: SumEncoding -> String # showList :: [SumEncoding] -> ShowS # |
A type-level indicator that ToJSON1
or FromJSON1
is being derived generically.
Instances
GFromJSON One Par1 | |
Defined in Data.Aeson.Types.FromJSON | |
GToJSON enc One Par1 | |
ToJSON1 f => GToJSON Encoding One (Rec1 f) | |
ToJSON1 f => GToJSON Value One (Rec1 f) | |
(ToJSON1 f, GToJSON Encoding One g) => GToJSON Encoding One (f :.: g) | |
(ToJSON1 f, GToJSON Value One g) => GToJSON Value One (f :.: g) | |
FromJSON1 f => GFromJSON One (Rec1 f) | |
Defined in Data.Aeson.Types.FromJSON | |
(FromJSON1 f, GFromJSON One g) => GFromJSON One (f :.: g) | |
Defined in Data.Aeson.Types.FromJSON |
aesonQQ :: QuasiQuoter #
A ThreadId
is an abstract type representing a handle to a thread.
ThreadId
is an instance of Eq
, Ord
and Show
, where
the Ord
instance implements an arbitrary total ordering over
ThreadId
s. The Show
instance lets you convert an arbitrary-valued
ThreadId
to string form; showing a ThreadId
value is occasionally
useful when debugging or diagnosing the behaviour of a concurrent
program.
Note: in GHC, if you have a ThreadId
, you essentially have
a pointer to the thread itself. This means the thread itself can't be
garbage collected until you drop the ThreadId
.
This misfeature will hopefully be corrected at a later date.
Instances
Eq ThreadId | Since: base-4.2.0.0 |
Ord ThreadId | Since: base-4.2.0.0 |
Defined in GHC.Conc.Sync | |
Show ThreadId | Since: base-4.2.0.0 |
Hashable ThreadId | |
Defined in Data.Hashable.Class | |
NFData ThreadId | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
PrimUnlifted ThreadId | Since: primitive-0.6.4.0 |
Defined in Data.Primitive.UnliftedArray toArrayArray# :: ThreadId -> ArrayArray# # fromArrayArray# :: ArrayArray# -> ThreadId # |
rtsSupportsBoundThreads :: Bool #
True
if bound threads are supported.
If rtsSupportsBoundThreads
is False
, isCurrentThreadBound
will always return False
and both forkOS
and runInBoundThread
will
fail.
Chan
is an abstract type representing an unbounded FIFO channel.
data SomeAsyncException where #
Superclass for asynchronous exceptions.
Since: base-4.7.0.0
Instances
Show SomeAsyncException | Since: base-4.7.0.0 |
Defined in GHC.IO.Exception showsPrec :: Int -> SomeAsyncException -> ShowS # show :: SomeAsyncException -> String # showList :: [SomeAsyncException] -> ShowS # | |
Exception SomeAsyncException | Since: base-4.7.0.0 |
Defined in GHC.IO.Exception |
data IOException #
Exceptions that occur in the IO
monad.
An IOException
records a more specific error type, a descriptive
string and maybe the handle that was used when the error was
flagged.
Instances
Eq IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception (==) :: IOException -> IOException -> Bool # (/=) :: IOException -> IOException -> Bool # | |
Show IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception showsPrec :: Int -> IOException -> ShowS # show :: IOException -> String # showList :: [IOException] -> ShowS # | |
Exception IOException | Since: base-4.1.0.0 |
Defined in GHC.IO.Exception | |
Error IOException | |
Defined in Control.Monad.Trans.Error noMsg :: IOException # strMsg :: String -> IOException # | |
Display IOException | Since: rio-0.1.0.0 |
Defined in RIO.Prelude.Display display :: IOException -> Utf8Builder # | |
MonadError IOException IO | |
Defined in Control.Monad.Error.Class throwError :: IOException -> IO a # catchError :: IO a -> (IOException -> IO a) -> IO a # |
class (Typeable e, Show e) => Exception e where #
Any type that you wish to throw or catch as an exception must be an
instance of the Exception
class. The simplest case is a new exception
type directly below the root:
data MyException = ThisException | ThatException deriving Show instance Exception MyException
The default method definitions in the Exception
class do what we need
in this case. You can now throw and catch ThisException
and
ThatException
as exceptions:
*Main> throw ThisException `catch` \e -> putStrLn ("Caught " ++ show (e :: MyException)) Caught ThisException
In more complicated examples, you may wish to define a whole hierarchy of exceptions:
--------------------------------------------------------------------- -- Make the root exception type for all the exceptions in a compiler data SomeCompilerException = forall e . Exception e => SomeCompilerException e instance Show SomeCompilerException where show (SomeCompilerException e) = show e instance Exception SomeCompilerException compilerExceptionToException :: Exception e => e -> SomeException compilerExceptionToException = toException . SomeCompilerException compilerExceptionFromException :: Exception e => SomeException -> Maybe e compilerExceptionFromException x = do SomeCompilerException a <- fromException x cast a --------------------------------------------------------------------- -- Make a subhierarchy for exceptions in the frontend of the compiler data SomeFrontendException = forall e . Exception e => SomeFrontendException e instance Show SomeFrontendException where show (SomeFrontendException e) = show e instance Exception SomeFrontendException where toException = compilerExceptionToException fromException = compilerExceptionFromException frontendExceptionToException :: Exception e => e -> SomeException frontendExceptionToException = toException . SomeFrontendException frontendExceptionFromException :: Exception e => SomeException -> Maybe e frontendExceptionFromException x = do SomeFrontendException a <- fromException x cast a --------------------------------------------------------------------- -- Make an exception type for a particular frontend compiler exception data MismatchedParentheses = MismatchedParentheses deriving Show instance Exception MismatchedParentheses where toException = frontendExceptionToException fromException = frontendExceptionFromException
We can now catch a MismatchedParentheses
exception as
MismatchedParentheses
, SomeFrontendException
or
SomeCompilerException
, but not other types, e.g. IOException
:
*Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: MismatchedParentheses)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeFrontendException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: SomeCompilerException)) Caught MismatchedParentheses *Main> throw MismatchedParentheses `catch` \e -> putStrLn ("Caught " ++ show (e :: IOException)) *** Exception: MismatchedParentheses
toException :: e -> SomeException #
fromException :: SomeException -> Maybe e #
displayException :: e -> String #
Render this exception value in a human-friendly manner.
Default implementation:
.show
Since: base-4.8.0.0
Instances
asProxyTypeOf :: a -> proxy a -> a #
asProxyTypeOf
is a type-restricted version of const
.
It is usually used as an infix operator, and its typing forces its first
argument (which is usually overloaded) to have the same type as the tag
of the second.
>>>
import Data.Word
>>>
:type asProxyTypeOf 123 (Proxy :: Proxy Word8)
asProxyTypeOf 123 (Proxy :: Proxy Word8) :: Word8
Note the lower-case proxy
in the definition. This allows any type
constructor with just one argument to be passed to the function, for example
we could also write
>>>
import Data.Word
>>>
:type asProxyTypeOf 123 (Just (undefined :: Word8))
asProxyTypeOf 123 (Just (undefined :: Word8)) :: Word8
data Proxy (t :: k) :: forall k. k -> * #
Proxy
is a type that holds no data, but has a phantom parameter of
arbitrary type (or even kind). Its use is to provide type information, even
though there is no value available of that type (or it may be too costly to
create one).
Historically,
is a safer alternative to the
Proxy
:: Proxy
a'undefined :: a'
idiom.
>>>
Proxy :: Proxy (Void, Int -> Int)
Proxy
Proxy can even hold types of higher kinds,
>>>
Proxy :: Proxy Either
Proxy
>>>
Proxy :: Proxy Functor
Proxy
>>>
Proxy :: Proxy complicatedStructure
Proxy
Instances
Generic1 (Proxy :: k -> *) | |
Monad (Proxy :: * -> *) | Since: base-4.7.0.0 |
Functor (Proxy :: * -> *) | Since: base-4.7.0.0 |
Applicative (Proxy :: * -> *) | Since: base-4.7.0.0 |
Foldable (Proxy :: * -> *) | Since: base-4.7.0.0 |
Defined in Data.Foldable fold :: Monoid m => Proxy m -> m # foldMap :: Monoid m => (a -> m) -> Proxy a -> m # foldr :: (a -> b -> b) -> b -> Proxy a -> b # foldr' :: (a -> b -> b) -> b -> Proxy a -> b # foldl :: (b -> a -> b) -> b -> Proxy a -> b # foldl' :: (b -> a -> b) -> b -> Proxy a -> b # foldr1 :: (a -> a -> a) -> Proxy a -> a # foldl1 :: (a -> a -> a) -> Proxy a -> a # elem :: Eq a => a -> Proxy a -> Bool # maximum :: Ord a => Proxy a -> a # minimum :: Ord a => Proxy a -> a # | |
Traversable (Proxy :: * -> *) | Since: base-4.7.0.0 |
ToJSON1 (Proxy :: * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a -> Value) -> ([a] -> Value) -> Proxy a -> Value # liftToJSONList :: (a -> Value) -> ([a] -> Value) -> [Proxy a] -> Value # liftToEncoding :: (a -> Encoding) -> ([a] -> Encoding) -> Proxy a -> Encoding # liftToEncodingList :: (a -> Encoding) -> ([a] -> Encoding) -> [Proxy a] -> Encoding # | |
FromJSON1 (Proxy :: * -> *) | |
Alternative (Proxy :: * -> *) | Since: base-4.9.0.0 |
MonadPlus (Proxy :: * -> *) | Since: base-4.9.0.0 |
Eq1 (Proxy :: * -> *) | Since: base-4.9.0.0 |
Ord1 (Proxy :: * -> *) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Read1 (Proxy :: * -> *) | Since: base-4.9.0.0 |
Defined in Data.Functor.Classes | |
Show1 (Proxy :: * -> *) | Since: base-4.9.0.0 |
NFData1 (Proxy :: * -> *) | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Hashable1 (Proxy :: * -> *) | |
Defined in Data.Hashable.Class | |
Bounded (Proxy t) | |
Enum (Proxy s) | Since: base-4.7.0.0 |
Eq (Proxy s) | Since: base-4.7.0.0 |
Data t => Data (Proxy t) | Since: base-4.7.0.0 |
Defined in Data.Data gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Proxy t -> c (Proxy t) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Proxy t) # toConstr :: Proxy t -> Constr # dataTypeOf :: Proxy t -> DataType # dataCast1 :: Typeable t0 => (forall d. Data d => c (t0 d)) -> Maybe (c (Proxy t)) # dataCast2 :: Typeable t0 => (forall d e. (Data d, Data e) => c (t0 d e)) -> Maybe (c (Proxy t)) # gmapT :: (forall b. Data b => b -> b) -> Proxy t -> Proxy t # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Proxy t -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Proxy t -> r # gmapQ :: (forall d. Data d => d -> u) -> Proxy t -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Proxy t -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Proxy t -> m (Proxy t) # | |
Ord (Proxy s) | Since: base-4.7.0.0 |
Read (Proxy t) | Since: base-4.7.0.0 |
Show (Proxy s) | Since: base-4.7.0.0 |
Ix (Proxy s) | Since: base-4.7.0.0 |
Generic (Proxy t) | |
Semigroup (Proxy s) | Since: base-4.9.0.0 |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Hashable (Proxy a) | |
Defined in Data.Hashable.Class | |
ToJSON (Proxy a) | |
Defined in Data.Aeson.Types.ToJSON | |
FromJSON (Proxy a) | |
NFData (Proxy a) | Since: deepseq-1.4.0.0 |
Defined in Control.DeepSeq | |
type Rep1 (Proxy :: k -> *) | |
type Rep (Proxy t) | |
A concrete, promotable proxy type, for use at the kind level There are no instances for this because it is intended at the kind level only
type family If (cond :: Bool) (tru :: k) (fls :: k) :: k where ... #
Type-level If. If True a b
==> a
; If False a b
==> b
An MVar
(pronounced "em-var") is a synchronising variable, used
for communication between concurrent threads. It can be thought of
as a a box, which may be empty or full.
Instances
NFData1 MVar | Since: deepseq-1.4.3.0 |
Defined in Control.DeepSeq | |
Eq (MVar a) | Since: base-4.1.0.0 |
NFData (MVar a) | NOTE: Only strict in the reference and not the referenced value. Since: deepseq-1.4.2.0 |
Defined in Control.DeepSeq | |
PrimUnlifted (MVar a) | Since: primitive-0.6.4.0 |
Defined in Data.Primitive.UnliftedArray toArrayArray# :: MVar a -> ArrayArray# # fromArrayArray# :: ArrayArray# -> MVar a # |
data SomeException where #
The SomeException
type is the root of the exception type hierarchy.
When an exception of type e
is thrown, behind the scenes it is
encapsulated in a SomeException
.
Instances
Show SomeException | Since: base-3.0 |
Defined in GHC.Exception showsPrec :: Int -> SomeException -> ShowS # show :: SomeException -> String # showList :: [SomeException] -> ShowS # | |
Exception SomeException | Since: base-3.0 |
Defined in GHC.Exception | |
Display SomeException | Since: rio-0.1.0.0 |
Defined in RIO.Prelude.Display display :: SomeException -> Utf8Builder # |
newtype MaybeT (m :: * -> *) a #
The parameterizable maybe monad, obtained by composing an arbitrary
monad with the Maybe
monad.
Computations are actions that may produce a value or exit.
The return
function yields a computation that produces that
value, while >>=
sequences two subcomputations, exiting if either
computation does.
Instances
newtype ExceptT e (m :: * -> *) a #
A monad transformer that adds exceptions to other monads.
ExceptT
constructs a monad parameterized over two things:
- e - The exception type.
- m - The inner monad.
The return
function yields a computation that produces the given
value, while >>=
sequences two subcomputations, exiting on the
first exception.
Instances
class MonadIO m => MonadUnliftIO (m :: * -> *) #
Monads which allow their actions to be run in IO
.
While MonadIO
allows an IO
action to be lifted into another
monad, this class captures the opposite concept: allowing you to
capture the monadic context. Note that, in order to meet the laws
given below, the intuition is that a monad must have no monadic
state, but may have monadic context. This essentially limits
MonadUnliftIO
to ReaderT
and IdentityT
transformers on top of
IO
.
Laws. For any value u
returned by askUnliftIO
, it must meet the
monad transformer laws as reformulated for MonadUnliftIO
:
unliftIO u . return = return
unliftIO u (m >>= f) = unliftIO u m >>= unliftIO u . f
The third is a currently nameless law which ensures that the current context is preserved.
askUnliftIO >>= (u -> liftIO (unliftIO u m)) = m
If you have a name for this, please submit it in a pull request for great glory.
Since: unliftio-core-0.1.0.0
Instances
MonadUnliftIO IO | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ResourceT m) | Since: resourcet-1.1.10 |
Defined in Control.Monad.Trans.Resource.Internal | |
MonadUnliftIO m => MonadUnliftIO (NoLoggingT m) | Since: monad-logger-0.3.26 |
Defined in Control.Monad.Logger askUnliftIO :: NoLoggingT m (UnliftIO (NoLoggingT m)) # withRunInIO :: ((forall a. NoLoggingT m a -> IO a) -> IO b) -> NoLoggingT m b # | |
MonadUnliftIO m => MonadUnliftIO (LoggingT m) | Since: monad-logger-0.3.26 |
Defined in Control.Monad.Logger | |
MonadUnliftIO (RIO env) | |
Defined in RIO.Prelude.RIO | |
MonadUnliftIO m => MonadUnliftIO (IdentityT m) | |
Defined in Control.Monad.IO.Unlift | |
MonadUnliftIO m => MonadUnliftIO (ReaderT r m) | |
Defined in Control.Monad.IO.Unlift |
A type class for extensible product.
We provide instances for tuples up to 12 elements by default.
You can define your own instance of Has
, but most of the time tuples will do fine.
Instances
Has a a | |
Has b (a, b) | |
Has a (a, b) | |
Has c (a, b, c) | |
Has b (a, b, c) | |
Has a (a, b, c) | |
Has d (a, b, c, d) | |
Has c (a, b, c, d) | |
Has b (a, b, c, d) | |
Has a (a, b, c, d) | |
Has e (a, b, c, d, e) | |
Has d (a, b, c, d, e) | |
Has c (a, b, c, d, e) | |
Has b (a, b, c, d, e) | |
Has a (a, b, c, d, e) | |
Has f (a, b, c, d, e, f) | |
Has e (a, b, c, d, e, f) | |
Has d (a, b, c, d, e, f) | |
Has c (a, b, c, d, e, f) | |
Has b (a, b, c, d, e, f) | |
Has a (a, b, c, d, e, f) | |
Has g (a, b, c, d, e, f, g) | |
Has f (a, b, c, d, e, f, g) | |
Has e (a, b, c, d, e, f, g) | |
Has d (a, b, c, d, e, f, g) | |
Has c (a, b, c, d, e, f, g) | |
Has b (a, b, c, d, e, f, g) | |
Has a (a, b, c, d, e, f, g) | |
Has h (a, b, c, d, e, f, g, h) | |
Has g (a, b, c, d, e, f, g, h) | |
Has f (a, b, c, d, e, f, g, h) | |
Has e (a, b, c, d, e, f, g, h) | |
Has d (a, b, c, d, e, f, g, h) | |
Has c (a, b, c, d, e, f, g, h) | |
Has b (a, b, c, d, e, f, g, h) | |
Has a (a, b, c, d, e, f, g, h) | |
Has i (a, b, c, d, e, f, g, h, i) | |
Has h (a, b, c, d, e, f, g, h, i) | |
Has g (a, b, c, d, e, f, g, h, i) | |
Has f (a, b, c, d, e, f, g, h, i) | |
Has e (a, b, c, d, e, f, g, h, i) | |
Has d (a, b, c, d, e, f, g, h, i) | |
Has c (a, b, c, d, e, f, g, h, i) | |
Has b (a, b, c, d, e, f, g, h, i) | |
Has a (a, b, c, d, e, f, g, h, i) | |
Has j (a, b, c, d, e, f, g, h, i, j) | |
Has i (a, b, c, d, e, f, g, h, i, j) | |
Has h (a, b, c, d, e, f, g, h, i, j) | |
Has g (a, b, c, d, e, f, g, h, i, j) | |
Has f (a, b, c, d, e, f, g, h, i, j) | |
Has e (a, b, c, d, e, f, g, h, i, j) | |
Has d (a, b, c, d, e, f, g, h, i, j) | |
Has c (a, b, c, d, e, f, g, h, i, j) | |
Has b (a, b, c, d, e, f, g, h, i, j) | |
Has a (a, b, c, d, e, f, g, h, i, j) | |
Has k (a, b, c, d, e, f, g, h, i, j, k) | |
Has j (a, b, c, d, e, f, g, h, i, j, k) | |
Has i (a, b, c, d, e, f, g, h, i, j, k) | |
Has h (a, b, c, d, e, f, g, h, i, j, k) | |
Has g (a, b, c, d, e, f, g, h, i, j, k) | |
Has f (a, b, c, d, e, f, g, h, i, j, k) | |
Has e (a, b, c, d, e, f, g, h, i, j, k) | |
Has d (a, b, c, d, e, f, g, h, i, j, k) | |
Has c (a, b, c, d, e, f, g, h, i, j, k) | |
Has b (a, b, c, d, e, f, g, h, i, j, k) | |
Has a (a, b, c, d, e, f, g, h, i, j, k) | |
Has l (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has k (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has j (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has i (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has h (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has g (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has f (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has e (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has d (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has c (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has b (a, b, c, d, e, f, g, h, i, j, k, l) | |
Has a (a, b, c, d, e, f, g, h, i, j, k, l) | |
registerGcMetrics :: Store -> IO () #
Register a number of metrics related to garbage collector behavior.
To enable GC statistics collection, either run your program with
+RTS -T
or compile it with
-with-rtsopts=-T
The runtime overhead of -T
is very small so it's safe to always
leave it enabled.
Registered counters:
rts.gc.bytes_allocated
- Total number of bytes allocated
rts.gc.num_gcs
- Number of garbage collections performed
rts.gc.num_bytes_usage_samples
- Number of byte usage samples taken
rts.gc.cumulative_bytes_used
- Sum of all byte usage samples, can be
used with
numByteUsageSamples
to calculate averages with arbitrary weighting (if you are sampling this record multiple times). rts.gc.bytes_copied
- Number of bytes copied during GC
rts.gc.mutator_cpu_ms
- CPU time spent running mutator threads, in milliseconds. This does not include any profiling overhead or initialization.
rts.gc.mutator_wall_ms
- Wall clock time spent running mutator threads, in milliseconds. This does not include initialization.
rts.gc.gc_cpu_ms
- CPU time spent running GC, in milliseconds.
rts.gc.gc_wall_ms
- Wall clock time spent running GC, in milliseconds.
rts.gc.cpu_ms
- Total CPU time elapsed since program start, in milliseconds.
rts.gc.wall_ms
- Total wall clock time elapsed since start, in milliseconds.
Registered gauges:
rts.gc.max_bytes_used
- Maximum number of live bytes seen so far
rts.gc.current_bytes_used
- Current number of live bytes
rts.gc.current_bytes_slop
- Current number of bytes lost to slop
rts.gc.max_bytes_slop
- Maximum number of bytes lost to slop at any one time so far
rts.gc.peak_megabytes_allocated
- Maximum number of megabytes allocated
rts.gc.par_tot_bytes_copied
- Number of bytes copied during GC, minus
space held by mutable lists held by the capabilities. Can be used
with
parMaxBytesCopied
to determine how well parallel GC utilized all cores. rts.gc.par_avg_bytes_copied
- Deprecated alias for
par_tot_bytes_copied
. rts.gc.par_max_bytes_copied
- Sum of number of bytes copied each GC by
the most active GC thread each GC. The ratio of
par_tot_bytes_copied
divided bypar_max_bytes_copied
approaches 1 for a maximally sequential run and approaches the number of threads (set by the RTS flag-N
) for a maximally parallel run.
serverMetricStore :: Server -> Store #
The metric store associated with the server. If you want to
add metric to the default store created by forkServer
you
need to use this function to retrieve it.
unsetEnvironment' :: ToEnv a => a -> IO (Either String ()) #
Unset Environment using a value of class ToEnv
unsetEnvironment :: EnvList a -> IO (Either String ()) #
Unset Environment from a ToEnv
constrained type
setEnvironment' :: ToEnv a => a -> IO (Either String ()) #
Set environment directly using a value of class ToEnv
gFromEnvCustom :: (DefConfig a, Generic a, GFromEnv (Rep a)) => Option -> Parser a #
Meant for specifying a custom Option
for environment retrieval
instance FromEnv PGConfig where fromEnv = gFromEnvCustom Option { dropPrefixCount = 8, customPrefix = "PG" }
Environment variable getter returning Maybe
Environment variable getter. Fails if the variable is not set or fails to parse.
runEnv :: Parser a -> IO (Either String a) #
For use with Generics, no FromEnv
typeclass necessary
getPgConfig :: IO (Either String ConnectInfo) getPgConfig = runEnv $ gFromEnvCustom defOption
Parser Monad for environment variable retrieval
Instances
Monad Parser | |
Functor Parser | |
Applicative Parser | |
Alternative Parser | |
MonadPlus Parser | |
MonadIO Parser | |
Defined in System.Envy | |
MonadError String Parser | |
Defined in System.Envy throwError :: String -> Parser a # catchError :: Parser a -> (String -> Parser a) -> Parser a # |
Type class for objects which have a default configuration.
For customizing environment variable generation
Option | |
|
Type class for objects which can be converted to a set of environment variable settings.
List of environment variables. Captures a "phantom type" which allows the type checker to detect the proper implementation of toEnv to use.
class Typeable a => Var a where #
Class for converting to / from an environment variable
Convert a value into an environment variable.
fromVar :: String -> Maybe a #
Parse an environment variable.
Instances
Var Bool | |
Var Double | |
Var Int | |
Var Int8 | |
Var Int16 | |
Var Int32 | |
Var Int64 | |
Var Integer | |
Var Word8 | |
Var Word16 | |
Var Word32 | |
Var Word64 | |
Var () | |
Var String | |
Var ByteString | |
Defined in System.Envy toVar :: ByteString -> String # fromVar :: String -> Maybe ByteString # | |
Var ByteString | |
Defined in System.Envy toVar :: ByteString -> String # fromVar :: String -> Maybe ByteString # | |
Var Text | |
Var UTCTime | |
Var Text | |
Var Day | |
Var a => Var (Maybe a) | |
failWithM :: Applicative m => e -> m (Maybe a) -> ExceptT e m a #
failWith :: Applicative m => e -> Maybe a -> ExceptT e m a #
(!?) :: Applicative m => m (Maybe a) -> e -> ExceptT e m a #
bimapExceptT :: Functor m => (e -> f) -> (a -> b) -> ExceptT e m a -> ExceptT f m b #
Transform the left and right value
exceptT :: Monad m => (a -> m c) -> (b -> m c) -> ExceptT a m b -> m c #
Fold an ExceptT
by providing one continuation for each constructor
Run multiple Either
computations and succeed if all of them succeed
mappend
s all successes or failures
Run multiple Either
computations and succeed if any of them succeed
mappend
s all successes or failures
runExceptT :: ExceptT e m a -> m (Either e a) #
The inverse of ExceptT
.
class MonadThrow m => MonadCatch (m :: * -> *) #
A class for monads which allow exceptions to be caught, in particular
exceptions which were thrown by throwM
.
Instances should obey the following law:
catch (throwM e) f = f e
Note that the ability to catch an exception does not guarantee that we can
deal with all possible exit points from a computation. Some monads, such as
continuation-based stacks, allow for more than just a success/failure
strategy, and therefore catch
cannot be used by those monads to properly
implement a function such as finally
. For more information, see
MonadMask
.
Instances
Logger Type.
LogNone | No logging. |
LogStdout BufSize | Logging to stdout.
|
LogStderr BufSize | Logging to stderr.
|
LogFileNoRotate FilePath BufSize | Logging to a file.
|
LogFile FileLogSpec BufSize | Logging to a file.
|
LogCallback (LogStr -> IO ()) (IO ()) | Logging with a log and flush action. run flush after log each message. |
The default buffer size (4,096 bytes).
encodePathSegmentsRelative :: [Text] -> Builder #
Like encodePathSegments, but without the initial slash.
class ToHttpApiData a where #
Convert value to HTTP API data.
WARNING: Do not derive this using DeriveAnyClass
as the generated
instance will loop indefinitely.
toUrlPiece :: a -> Text #
Convert to URL path piece.
toEncodedUrlPiece :: a -> Builder #
Convert to a URL path piece, making sure to encode any special chars.
The default definition uses encodePathSegmentsRelative
,
but this may be overriden with a more efficient version.
toHeader :: a -> ByteString #
Convert to HTTP header value.
toQueryParam :: a -> Text #
Convert to query param value.
Instances
class FromHttpApiData a where #
Parse value from HTTP API data.
WARNING: Do not derive this using DeriveAnyClass
as the generated
instance will loop indefinitely.
parseUrlPiece :: Text -> Either Text a #
Parse URL path piece.
parseHeader :: ByteString -> Either Text a #
Parse HTTP header value.
parseQueryParam :: Text -> Either Text a #
Parse query param value.
Instances
Represents a general universal resource identifier using its component parts.
For example, for the URI
foo://anonymous@www.haskell.org:42/ghc?query#frag
the components are:
Instances
Eq URI | |
Data URI | |
Defined in Network.URI gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> URI -> c URI # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c URI # dataTypeOf :: URI -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c URI) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c URI) # gmapT :: (forall b. Data b => b -> b) -> URI -> URI # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> URI -> r # gmapQ :: (forall d. Data d => d -> u) -> URI -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> URI -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> URI -> m URI # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> URI -> m URI # | |
Ord URI | |
Show URI | |
Generic URI | |
NFData URI | |
Defined in Network.URI | |
type Rep URI | |
Defined in Network.URI type Rep URI = D1 (MetaData "URI" "Network.URI" "network-uri-2.6.1.0-AstEwZoXrlUJQq4VkxaVo9" 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))))) |
responseTimeoutDefault :: ResponseTimeout #
Use the default response timeout
When used on a Request
, means: use the manager's timeout value
When used on a ManagerSettings
, means: default to 30 seconds
Since: http-client-0.5.0
responseTimeoutNone :: ResponseTimeout #
Do not have a response timeout
Since: http-client-0.5.0
responseTimeoutMicro :: Int -> ResponseTimeout #
Specify a response timeout in microseconds
Since: http-client-0.5.0
managerSetProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings #
Set the proxy override value, for both HTTP (insecure) and HTTPS (insecure) connections.
Since 0.4.7
managerSetSecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings #
Set the proxy override value, only for HTTPS (secure) connections.
Since 0.4.7
managerSetInsecureProxy :: ProxyOverride -> ManagerSettings -> ManagerSettings #
Set the proxy override value, only for HTTP (insecure) connections.
Since 0.4.7
withResponseHistory :: Request -> Manager -> (HistoriedResponse BodyReader -> IO a) -> IO a #
A variant of withResponse
which keeps a history of all redirects
performed in the interim, together with the first 1024 bytes of their
response bodies.
Since 0.4.1
responseOpenHistory :: Request -> Manager -> IO (HistoriedResponse BodyReader) #
A variant of responseOpen
which keeps a history of all redirects
performed in the interim, together with the first 1024 bytes of their
response bodies.
Since 0.4.1
data HistoriedResponse body #
A datatype holding information on redirected requests and the final response.
Since 0.4.1
Instances
withConnection :: Request -> Manager -> (Connection -> IO a) -> IO a #
Perform an action using a Connection
acquired from the given Manager
.
You should use this only when you have to read and write interactively through the connection (e.g. connection by the WebSocket protocol).
Since: http-client-0.5.13
responseClose :: Response a -> IO () #
Close any open resources associated with the given Response
. In general,
this will either close an active Connection
or return it to the Manager
to be reused.
Since 0.1.0
responseOpen :: Request -> Manager -> IO (Response BodyReader) #
The most low-level function for initiating an HTTP request.
The first argument to this function gives a full specification
on the request: the host to connect to, whether to use SSL,
headers, etc. Please see Request
for full details. The
second argument specifies which Manager
should be used.
This function then returns a Response
with a
BodyReader
. The Response
contains the status code
and headers that were sent back to us, and the
BodyReader
contains the body of the request. Note
that this BodyReader
allows you to have fully
interleaved IO actions during your HTTP download, making it
possible to download very large responses in constant memory.
An important note: the response body returned by this function represents a
live HTTP connection. As such, if you do not use the response body, an open
socket will be retained indefinitely. You must be certain to call
responseClose
on this response to free up resources.
This function automatically performs any necessary redirects, as specified
by the redirectCount
setting.
When implementing a (reverse) proxy using this function or relating functions, it's wise to remove Transfer-Encoding:, Content-Length:, Content-Encoding: and Accept-Encoding: from request and response headers to be relayed.
Since 0.1.0
httpNoBody :: Request -> Manager -> IO (Response ()) #
A convenient wrapper around withResponse
which ignores the response
body. This is useful, for example, when performing a HEAD request.
Since 0.3.2
httpLbs :: Request -> Manager -> IO (Response ByteString) #
A convenience wrapper around withResponse
which reads in the entire
response body and immediately closes the connection. Note that this function
performs fully strict I/O, and only uses a lazy ByteString in its response
for memory efficiency. If you are anticipating a large response body, you
are encouraged to use withResponse
and brRead
instead.
Since 0.1.0
withResponse :: Request -> Manager -> (Response BodyReader -> IO a) -> IO a #
Perform a Request
using a connection acquired from the given Manager
,
and then provide the Response
to the given function. This function is
fully exception safe, guaranteeing that the response will be closed when the
inner function exits. It is defined as:
withResponse req man f = bracket (responseOpen req man) responseClose f
It is recommended that you use this function in place of explicit calls to
responseOpen
and responseClose
.
You will need to use functions such as brRead
to consume the response
body.
Since 0.1.0
:: SetCookie | The |
-> Request | The request that originated the response that yielded the |
-> UTCTime | Value that should be used as "now" |
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that) |
-> Maybe Cookie | The optional output cookie |
Turn a SetCookie into a Cookie, if it is valid
:: Cookie | The |
-> CookieJar | Input cookie jar to modify |
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that) |
-> CookieJar | Updated (or not) cookie jar |
Insert a cookie created by generateCookie into the cookie jar (or not if it shouldn't be allowed in)
:: SetCookie | The |
-> Request | The request that originated the response that yielded the |
-> UTCTime | Value that should be used as "now" |
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that) |
-> CookieJar | Input cookie jar to modify |
-> CookieJar | Updated cookie jar |
This corresponds to the algorithm described in Section 5.3 "Storage Model"
This function consists of calling generateCookie
followed by insertCheckedCookie
.
Use this function if you plan to do both in a row.
generateCookie
and insertCheckedCookie
are only provided for more fine-grained control.
:: Response a | Response received from server |
-> Request | Request which generated the response |
-> UTCTime | Value that should be used as "now" |
-> CookieJar | Current cookie jar |
-> (CookieJar, Response a) | (Updated cookie jar with cookies from the Response, The response stripped of any "Set-Cookie" header) |
This applies receiveSetCookie
to a given Response
:: Request | Input request |
-> CookieJar | Current cookie jar |
-> UTCTime | Value that should be used as "now" |
-> Bool | Whether or not this request is coming from an "http" source (not javascript or anything like that) |
-> (ByteString, CookieJar) | (Contents of a "Cookie" header, Updated cookie jar (last-access-time is updated)) |
This corresponds to the algorithm described in Section 5.4 "The Cookie Header"
:: Request | The request to insert into |
-> CookieJar | Current cookie jar |
-> UTCTime | Value that should be used as "now" |
-> (Request, CookieJar) | (Output request, Updated cookie jar (last-access-time is updated)) |
This applies the computeCookieString
to a given Request
:: CookieJar | Input cookie jar |
-> UTCTime | Value that should be used as "now" |
-> CookieJar | Filtered cookie jar |
This corresponds to the eviction algorithm described in Section 5.3 "Storage Model"
destroyCookieJar :: CookieJar -> [Cookie] #
createCookieJar :: [Cookie] -> CookieJar #
pathMatches :: ByteString -> ByteString -> Bool #
This corresponds to the subcomponent algorithm entitled "Path-Match" detailed in section 5.1.4
defaultPath :: Request -> ByteString #
This corresponds to the subcomponent algorithm entitled "Paths" detailed in section 5.1.4
:: ByteString | Domain to test |
-> ByteString | Domain from a cookie |
-> Bool |
This corresponds to the subcomponent algorithm entitled "Domain Matching" detailed in section 5.1.3
isIpAddress :: ByteString -> Bool #
defaultProxy :: ProxyOverride #
The default proxy settings for a manager. In particular: if the http_proxy
(or https_proxy
) environment variable is set, use it. Otherwise, use the values in the Request
.
Since 0.4.7
:: Text | environment variable name |
-> Maybe Proxy | fallback if no environment set |
-> ProxyOverride |
Same as proxyEnvironment
, but instead of default environment variable
names, allows you to set your own name.
Since 0.4.7
:: Maybe Proxy | fallback if no environment set |
-> ProxyOverride |
useProxy :: Proxy -> ProxyOverride #
Use the given proxy settings, regardless of the proxy value in the Request
.
Since 0.4.7
Never connect using a proxy, regardless of the proxy value in the Request
.
Since 0.4.7
proxyFromRequest :: ProxyOverride #
Get the proxy settings from the Request
itself.
Since 0.4.7
withManager :: ManagerSettings -> (Manager -> IO a) -> IO a #
Create, use and close a Manager
.
Since 0.2.1
closeManager :: Manager -> IO () #
Close all connections in a Manager
.
Note that this doesn't affect currently in-flight connections, meaning you can safely use it without hurting any queries you may have concurrently running.
Since 0.1.0
newManager :: ManagerSettings -> IO Manager #
Create a Manager
. The Manager
will be shut down automatically via
garbage collection.
Creating a new Manager
is a relatively expensive operation, you are
advised to share a single Manager
between requests instead.
The first argument to this function is often defaultManagerSettings
,
though add-on libraries may provide a recommended replacement.
Since 0.1.0
defaultManagerSettings :: ManagerSettings #
Default value for ManagerSettings
.
Note that this value does not have support for SSL/TLS. If you need to
make any https connections, please use the http-client-tls package, which
provides a tlsManagerSettings
value.
Since 0.1.0
rawConnectionModifySocketSize :: (Socket -> IO ()) -> IO (Int -> Maybe HostAddress -> String -> Int -> IO Connection) #
Same as rawConnectionModifySocket
, but also takes in a chunk size.
Since: http-client-0.5.2
rawConnectionModifySocket :: (Socket -> IO ()) -> IO (Maybe HostAddress -> String -> Int -> IO Connection) #
A value for the managerRawConnection
setting, but also allows you to
modify the underlying Socket
to set additional settings. For a motivating
use case, see: https://github.com/snoyberg/http-client/issues/71.
Since 0.3.8
observedStreamFile :: (StreamFileStatus -> IO ()) -> FilePath -> IO RequestBody #
Send a file as the request body, while observing streaming progress via
a PopObserver
. Observations are made between reading and sending a chunk.
It is expected that the file size does not change between calling
observedStreamFile
and making any requests using this request body.
Since 0.4.9
streamFile :: FilePath -> IO RequestBody #
Send a file as the request body.
It is expected that the file size does not change between calling
streamFile
and making any requests using this request body.
Since 0.4.9
setQueryStringPartialEscape :: [(ByteString, [EscapeItem])] -> Request -> Request #
Set the query string to the given key/value pairs.
Since: http-client-0.5.10
setQueryString :: [(ByteString, Maybe ByteString)] -> Request -> Request #
Set the query string to the given key/value pairs.
Since 0.3.6
setRequestCheckStatus :: Request -> Request #
Modify the request so that non-2XX status codes generate a runtime
StatusCodeException
, by using throwErrorStatusCodes
Since: http-client-0.5.13
setRequestIgnoreStatus :: Request -> Request #
Modify the request so that non-2XX status codes do not generate a runtime
StatusCodeException
.
Since: http-client-0.4.29
urlEncodedBody :: [(ByteString, ByteString)] -> Request -> Request #
Add url-encoded parameters to the Request
.
This sets a new requestBody
, adds a content-type request header and
changes the method
to POST.
Since 0.1.0
applyBasicProxyAuth :: ByteString -> ByteString -> Request -> Request #
Add a Proxy-Authorization header (with the specified username and
password) to the given Request
. Ignore error handling:
applyBasicProxyAuth "user" "pass" <$> parseRequest "http://example.org"
Since 0.3.4
applyBasicAuth :: ByteString -> ByteString -> Request -> Request #
Add a Basic Auth header (with the specified user name and password) to the given Request. Ignore error handling:
applyBasicAuth "user" "pass" $ parseRequest_ url
NOTE: The function applyDigestAuth
is provided by the http-client-tls
package instead of this package due to extra dependencies. Please use that
package if you need to use digest authentication.
Since 0.1.0
A default request value, a GET request of localhost/:80, with an empty request body.
Note that the default checkResponse
does nothing.
Since: http-client-0.4.30
requestFromURI_ :: URI -> Request #
Same as requestFromURI
, but if the conversion would fail,
throws an impure exception.
Since: http-client-0.5.12
requestFromURI :: MonadThrow m => URI -> m Request #
This can fail if the given URI
is not absolute, or if the
URI
scheme is not "http"
or "https"
. In these cases the function
will throw an error via MonadThrow
.
This function defaults some of the values in Request
, such as setting method
to
GET
and requestHeaders
to []
.
A Request
created by this function won't cause exceptions on non-2XX
response status codes.
Since: http-client-0.5.12
parseRequest_ :: String -> Request #
Same as parseRequest
, but parse errors cause an impure exception.
Mostly useful for static strings which are known to be correctly
formatted.
parseRequest :: MonadThrow m => String -> m Request #
Convert a URL into a Request
.
This function defaults some of the values in Request
, such as setting method
to
GET
and requestHeaders
to []
.
Since this function uses MonadThrow
, the return monad can be anything that is
an instance of MonadThrow
, such as IO
or Maybe
.
You can place the request method at the beginning of the URL separated by a space, e.g.:
@@
parseRequest "POST http://httpbin.org/post"
@@
Note that the request method must be provided as all capital letters.
A Request
created by this function won't cause exceptions on non-2XX
response status codes.
To create a request which throws on non-2XX status codes, see parseUrlThrow
Since: http-client-0.4.30
throwErrorStatusCodes :: MonadIO m => Request -> Response BodyReader -> m () #
Throws a StatusCodeException
wrapped in HttpExceptionRequest
,
if the response's status code indicates an error (if it isn't 2xx).
This can be used to implement checkResponse
.
Since: http-client-0.5.13
parseUrlThrow :: MonadThrow m => String -> m Request #
Same as parseRequest
, except will throw an HttpException
in the
event of a non-2XX response. This uses throwErrorStatusCodes
to
implement checkResponse
.
Since: http-client-0.4.30
parseUrl :: MonadThrow m => String -> m Request #
Deprecated synonym for parseUrlThrow
. You probably want
parseRequest
or parseRequest_
instead.
Since: http-client-0.1.0
brConsume :: BodyReader -> IO [ByteString] #
Strictly consume all remaining chunks of data from the stream.
Since 0.1.0
brReadSome :: BodyReader -> Int -> IO ByteString #
Continuously call brRead
, building up a lazy ByteString until a chunk is
constructed that is at least as many bytes as requested.
Since 0.4.20
brRead :: BodyReader -> IO ByteString #
Get a single chunk of data from the response body, or an empty bytestring if no more data is available.
Note that in order to consume the entire request body, you will need to
repeatedly call this function until you receive an empty ByteString
as a
result.
Since 0.1.0
:: Socket | |
-> Int | chunk size |
-> IO Connection |
Create a new Connection
from a Socket
.
Since: http-client-0.5.3
:: IO ByteString | read |
-> (ByteString -> IO ()) | write |
-> IO () | close |
-> IO Connection |
Create a new Connection
from a read, write, and close function.
Since: http-client-0.5.3
type BodyReader = IO ByteString #
An IO
action that represents an incoming response body coming from the
server. Data provided by this action has already been gunzipped and
de-chunked, and respects any content-length headers present.
The action gets a single chunk of data from the response body, or an empty bytestring if no more data is available.
Since 0.4.0
data HttpException #
An exception which may be generated by this library
Since: http-client-0.5.0
HttpExceptionRequest Request HttpExceptionContent | Most exceptions are specific to a Since: http-client-0.5.0 |
InvalidUrlException String String | A URL (first field) is invalid for a given reason (second argument). Since: http-client-0.5.0 |
Instances
Show HttpException | |
Defined in Network.HTTP.Client.Types showsPrec :: Int -> HttpException -> ShowS # show :: HttpException -> String # showList :: [HttpException] -> ShowS # | |
Exception HttpException | |
Defined in Network.HTTP.Client.Types |
data HttpExceptionContent #
StatusCodeException (Response ()) ByteString | Generated by the May include the beginning of the response body. Since: http-client-0.5.0 |
TooManyRedirects [Response ByteString] | The server responded with too many redirects for a request. Contains the list of encountered responses containing redirects in reverse chronological order; including last redirect, which triggered the exception and was not followed. Since: http-client-0.5.0 |
OverlongHeaders | Either too many headers, or too many total bytes in a single header, were returned by the server, and the memory exhaustion protection in this library has kicked in. Since: http-client-0.5.0 |
ResponseTimeout | The server took too long to return a response. This can
be altered via Since: http-client-0.5.0 |
ConnectionTimeout | Attempting to connect to the server timed out. Since: http-client-0.5.0 |
ConnectionFailure SomeException | An exception occurred when trying to connect to the server. Since: http-client-0.5.0 |
InvalidStatusLine ByteString | The status line returned by the server could not be parsed. Since: http-client-0.5.0 |
InvalidHeader ByteString | The given response header line could not be parsed Since: http-client-0.5.0 |
InternalException SomeException | An exception was raised by an underlying library when performing the request. Most often, this is caused by a failing socket action or a TLS exception. Since: http-client-0.5.0 |
ProxyConnectException ByteString Int Status | A non-200 status code was returned when trying to connect to the proxy server on the given host and port. Since: http-client-0.5.0 |
NoResponseDataReceived | No response data was received from the server at all. This exception may deserve special handling within the library, since it may indicate that a pipelining has been used, and a connection thought to be open was in fact closed. Since: http-client-0.5.0 |
TlsNotSupported | Exception thrown when using a Since: http-client-0.5.0 |
WrongRequestBodyStreamSize Word64 Word64 | The request body provided did not match the expected size. Provides the expected and actual size. Since: http-client-0.4.31 |
ResponseBodyTooShort Word64 Word64 | The returned response body is too short. Provides the expected size and actual size. Since: http-client-0.5.0 |
InvalidChunkHeaders | A chunked response body had invalid headers. Since: http-client-0.5.0 |
IncompleteHeaders | An incomplete set of response headers were returned. Since: http-client-0.5.0 |
InvalidDestinationHost ByteString | The host we tried to connect to is invalid (e.g., an empty string). |
HttpZlibException ZlibException | An exception was thrown when inflating a response body. Since: http-client-0.5.0 |
InvalidProxyEnvironmentVariable Text Text | Values in the proxy environment variable were invalid. Provides the environment variable name and its value. Since: http-client-0.5.0 |
ConnectionClosed | Attempted to use a Since: http-client-0.5.0 |
InvalidProxySettings Text | Proxy settings are not valid (Windows specific currently) @since 0.5.7 |
Instances
Show HttpExceptionContent | |
Defined in Network.HTTP.Client.Types showsPrec :: Int -> HttpExceptionContent -> ShowS # show :: HttpExceptionContent -> String # showList :: [HttpExceptionContent] -> ShowS # |
proxyHost :: Proxy -> ByteString #
The host name of the HTTP proxy.
data RequestBody #
When using one of the RequestBodyStream
/ RequestBodyStreamChunked
constructors, you must ensure that the GivesPopper
can be called multiple
times. Usually this is not a problem.
The RequestBodyStreamChunked
will send a chunked request body. Note that
not all servers support this. Only use RequestBodyStreamChunked
if you
know the server you're sending to supports chunked request bodies.
Since 0.1.0
RequestBodyLBS ByteString | |
RequestBodyBS ByteString | |
RequestBodyBuilder Int64 Builder | |
RequestBodyStream Int64 (GivesPopper ()) | |
RequestBodyStreamChunked (GivesPopper ()) | |
RequestBodyIO (IO RequestBody) | Allows creation of a Since: http-client-0.4.28 |
Instances
IsString RequestBody | Since 0.4.12 |
Defined in Network.HTTP.Client.Types fromString :: String -> RequestBody # | |
Semigroup RequestBody | |
Defined in Network.HTTP.Client.Types (<>) :: RequestBody -> RequestBody -> RequestBody # sconcat :: NonEmpty RequestBody -> RequestBody # stimes :: Integral b => b -> RequestBody -> RequestBody # | |
Monoid RequestBody | |
Defined in Network.HTTP.Client.Types mempty :: RequestBody # mappend :: RequestBody -> RequestBody -> RequestBody # mconcat :: [RequestBody] -> RequestBody # |
type Popper = IO ByteString #
A function which generates successive chunks of a request body, provider a single empty bytestring when no more data is available.
Since 0.1.0
type NeedsPopper a = Popper -> IO a #
A function which must be provided with a Popper
.
Since 0.1.0
type GivesPopper a = NeedsPopper a -> IO a #
A function which will provide a Popper
to a NeedsPopper
. This
seemingly convoluted structure allows for creation of request bodies which
allocate scarce resources in an exception safe manner.
Since 0.1.0
All information on how to connect to a host and what should be sent in the HTTP request.
If you simply wish to download from a URL, see parseRequest
.
The constructor for this data type is not exposed. Instead, you should use
either the defaultRequest
value, or parseRequest
to
construct from a URL, and then use the records below to make modifications.
This approach allows http-client to add configuration options without
breaking backwards compatibility.
For example, to construct a POST request, you could do something like:
initReq <- parseRequest "http://www.example.com/path" let req = initReq { method = "POST" }
For more information, please see http://www.yesodweb.com/book/settings-types.
Since 0.1.0
data ResponseTimeout #
How to deal with timing out a response
Since: http-client-0.5.0
Instances
Eq ResponseTimeout | |
Defined in Network.HTTP.Client.Types (==) :: ResponseTimeout -> ResponseTimeout -> Bool # (/=) :: ResponseTimeout -> ResponseTimeout -> Bool # | |
Show ResponseTimeout | |
Defined in Network.HTTP.Client.Types showsPrec :: Int -> ResponseTimeout -> ShowS # show :: ResponseTimeout -> String # showList :: [ResponseTimeout] -> ShowS # |
A simple representation of the HTTP response.
Since 0.1.0
Instances
Functor Response | |
Foldable Response | |
Defined in Network.HTTP.Client.Types fold :: Monoid m => Response m -> m # foldMap :: Monoid m => (a -> m) -> Response a -> m # foldr :: (a -> b -> b) -> b -> Response a -> b # foldr' :: (a -> b -> b) -> b -> Response a -> b # foldl :: (b -> a -> b) -> b -> Response a -> b # foldl' :: (b -> a -> b) -> b -> Response a -> b # foldr1 :: (a -> a -> a) -> Response a -> a # foldl1 :: (a -> a -> a) -> Response a -> a # elem :: Eq a => a -> Response a -> Bool # maximum :: Ord a => Response a -> a # minimum :: Ord a => Response a -> a # | |
Traversable Response | |
Eq body => Eq (Response body) | |
Show body => Show (Response body) | |
data ManagerSettings #
Settings for a Manager
. Please use the defaultManagerSettings
function and then modify
individual settings. For more information, see http://www.yesodweb.com/book/settings-types.
Since 0.1.0
data ProxyOverride #
How the HTTP proxy server settings should be discovered.
Since 0.4.7
Keeps track of open connections for keep-alive.
If possible, you should share a single Manager
between multiple threads and requests.
Since 0.1.0
Instances
HasHttpManager Manager | |
Defined in Network.HTTP.Client.Types getHttpManager :: Manager -> Manager # |
class HasHttpManager a where #
getHttpManager :: a -> Manager #
Instances
Has ModHttpClient α => HasHttpManager α # | |
Defined in Magicbane.Has getHttpManager :: α -> Manager # | |
HasHttpManager Manager | |
Defined in Network.HTTP.Client.Types getHttpManager :: Manager -> Manager # |
data StreamFileStatus #
Status of streaming a request body from a file.
Since 0.4.9
Instances
Eq StreamFileStatus | |
Defined in Network.HTTP.Client.Types (==) :: StreamFileStatus -> StreamFileStatus -> Bool # (/=) :: StreamFileStatus -> StreamFileStatus -> Bool # | |
Ord StreamFileStatus | |
Defined in Network.HTTP.Client.Types compare :: StreamFileStatus -> StreamFileStatus -> Ordering # (<) :: StreamFileStatus -> StreamFileStatus -> Bool # (<=) :: StreamFileStatus -> StreamFileStatus -> Bool # (>) :: StreamFileStatus -> StreamFileStatus -> Bool # (>=) :: StreamFileStatus -> StreamFileStatus -> Bool # max :: StreamFileStatus -> StreamFileStatus -> StreamFileStatus # min :: StreamFileStatus -> StreamFileStatus -> StreamFileStatus # | |
Show StreamFileStatus | |
Defined in Network.HTTP.Client.Types showsPrec :: Int -> StreamFileStatus -> ShowS # show :: StreamFileStatus -> String # showList :: [StreamFileStatus] -> ShowS # |
Query.
General form: a=b&c=d, but if the value is Nothing, it becomes a&c=d.
writeLinkHeader :: [Link] -> Text #
parseLinkHeaderBS :: ByteString -> Maybe [Link] #
Parses a Link header, returns a Maybe.
parseLinkHeaderBS' :: ByteString -> Either String [Link] #
Parses a Link header, returns an Either, where Left is the Attoparsec error string (probably not a useful one).
parseLinkHeader :: Text -> Maybe [Link] #
Parses a Link header, returns a Maybe.
parseLinkHeader' :: Text -> Either String [Link] #
Parses a Link header, returns an Either, where Left is the Attoparsec error string (probably not a useful one).
linkHeader :: Parser [Link] #
The Attoparsec parser for the Link header.
linkParams :: Link -> [(LinkParam, Text)] #
Extracts the parameters from the link.
The link attribute key.
http20 :: HttpVersion #
HTTP 2.0
http11 :: HttpVersion #
HTTP 1.1
http10 :: HttpVersion #
HTTP 1.0
http09 :: HttpVersion #
HTTP 0.9
data HttpVersion #
HTTP Version.
Note that the Show instance is intended merely for debugging.
Instances
Types which can, and commonly are, converted to Query
are in this class.
You can use lists of simple key value pairs, with ByteString
(strict, or lazy:
ByteString
), Text
, or String
as the key/value types. You can also have the value
type lifted into a Maybe to support keys without values; and finally it is possible to put
each pair into a Maybe for key-value pairs that aren't always present.
Instances
(QueryKeyLike k, QueryValueLike v) => QueryLike [Maybe (k, v)] | |
Defined in Network.HTTP.Types.QueryLike | |
(QueryKeyLike k, QueryValueLike v) => QueryLike [(k, v)] | |
Defined in Network.HTTP.Types.QueryLike |
renderQueryBuilderPartialEscape #
:: Bool | prepend a question mark? |
-> PartialEscapeQuery | |
-> Builder |
Convert PartialEscapeQuery
to a Builder
.
:: Bool | prepend question mark? |
-> PartialEscapeQuery | |
-> ByteString |
Convert PartialEscapeQuery
to ByteString
.
decodePath :: ByteString -> ([Text], Query) #
Decode a whole path (path segments + query).
encodePath :: [Text] -> Query -> Builder #
Encode a whole path (path segments + query).
extractPath :: ByteString -> ByteString #
Extract whole path (path segments + query) from a RFC 2616 Request-URI.
>>>
extractPath "/path"
"/path"
>>>
extractPath "http://example.com:8080/path"
"/path"
>>>
extractPath "http://example.com"
"/"
>>>
extractPath ""
"/"
decodePathSegments :: ByteString -> [Text] #
Parse a list of path segments from a valid URL fragment.
encodePathSegments :: [Text] -> Builder #
Encodes a list of path segments into a valid URL fragment.
This function takes the following three steps:
- UTF-8 encodes the characters.
- Performs percent encoding on all unreserved characters, as well as :@=+$,
- Prepends each segment with a slash.
For example:
encodePathSegments [\"foo\", \"bar\", \"baz\"]
"/foo/bar/baz"
encodePathSegments [\"foo bar\", \"baz\/bin\"]
"/foo%20bar/baz%2Fbin"
encodePathSegments [\"שלום\"]
"/%D7%A9%D7%9C%D7%95%D7%9D"
Huge thanks to Jeremy Shaw who created the original implementation of this function in web-routes and did such thorough research to determine all correct escaping procedures.
:: Bool | Whether to decode |
-> ByteString | The ByteString to encode as URL |
-> ByteString | The encoded URL |
Percent-encoding for URLs.
:: Bool | Whether input is in query string. True: Query string, False: Path element |
-> ByteString | |
-> Builder |
Percent-encoding for URLs (using Builder
).
parseSimpleQuery :: ByteString -> SimpleQuery #
Parse SimpleQuery
from a ByteString
.
parseQuery :: ByteString -> Query #
Split out the query string into a list of keys and values. A few importants points:
- The result returned is still bytestrings, since we perform no character decoding here. Most likely, you will want to use UTF-8 decoding, but this is left to the user of the library.
- Percent decoding errors are ignored. In particular, "%Q" will be output as "%Q".
:: Bool | prepend question mark? |
-> SimpleQuery | |
-> ByteString |
Convert SimpleQuery
to ByteString
.
simpleQueryToQuery :: SimpleQuery -> Query #
Convert SimpleQuery
to Query
.
parseQueryText :: ByteString -> QueryText #
Parse QueryText
from a ByteString
. See parseQuery
for details.
type QueryItem = (ByteString, Maybe ByteString) #
Query item
type QueryText = [(Text, Maybe Text)] #
Like Query, but with Text
instead of ByteString
(UTF8-encoded).
type SimpleQueryItem = (ByteString, ByteString) #
Simplified Query item type without support for parameter-less items.
type SimpleQuery = [SimpleQueryItem] #
Simplified Query type without support for parameter-less items.
data EscapeItem #
For some URIs characters must not be URI encoded,
eg +
or :
in q=a+language:haskell+created:2009-01-01..2009-02-01&sort=stars
The character list unreservedPI instead of unreservedQS would solve this.
But we explicitly decide what part to encode.
This is mandatory when searching for +
: q=%2B+language:haskell.
Instances
Eq EscapeItem | |
Defined in Network.HTTP.Types.URI (==) :: EscapeItem -> EscapeItem -> Bool # (/=) :: EscapeItem -> EscapeItem -> Bool # | |
Ord EscapeItem | |
Defined in Network.HTTP.Types.URI compare :: EscapeItem -> EscapeItem -> Ordering # (<) :: EscapeItem -> EscapeItem -> Bool # (<=) :: EscapeItem -> EscapeItem -> Bool # (>) :: EscapeItem -> EscapeItem -> Bool # (>=) :: EscapeItem -> EscapeItem -> Bool # max :: EscapeItem -> EscapeItem -> EscapeItem # min :: EscapeItem -> EscapeItem -> EscapeItem # | |
Show EscapeItem | |
Defined in Network.HTTP.Types.URI showsPrec :: Int -> EscapeItem -> ShowS # show :: EscapeItem -> String # showList :: [EscapeItem] -> ShowS # |
type PartialEscapeQueryItem = (ByteString, [EscapeItem]) #
Query item
type PartialEscapeQuery = [PartialEscapeQueryItem] #
Query with some chars that should not be escaped.
General form: a=b&c=d:e+f&g=h
statusIsServerError :: Status -> Bool #
Server Error class
statusIsClientError :: Status -> Bool #
Client Error class
statusIsRedirection :: Status -> Bool #
Redirection class
statusIsSuccessful :: Status -> Bool #
Successful class
statusIsInformational :: Status -> Bool #
Informational class
networkAuthenticationRequired511 :: Status #
Network Authentication Required 511 (RFC 6585)
httpVersionNotSupported505 :: Status #
HTTP Version Not Supported 505
Gateway Timeout 504
serviceUnavailable503 :: Status #
Service Unavailable 503
badGateway502 :: Status #
Bad Gateway 502
Not Implemented 501
internalServerError500 :: Status #
Internal Server Error 500
requestHeaderFieldsTooLarge431 :: Status #
Request Header Fields Too Large 431 (RFC 6585)
tooManyRequests429 :: Status #
Too Many Requests 429 (RFC 6585)
preconditionRequired428 :: Status #
Precondition Required 428 (RFC 6585)
unprocessableEntity422 :: Status #
Unprocessable Entity 422 (RFC 4918)
imATeapot418 :: Status #
I'm a teapot 418
expectationFailed417 :: Status #
Expectation Failed 417
requestedRangeNotSatisfiable416 :: Status #
Requested Range Not Satisfiable 416
unsupportedMediaType415 :: Status #
Unsupported Media Type 415
requestURITooLong414 :: Status #
Request-URI Too Long 414
requestEntityTooLarge413 :: Status #
Request Entity Too Large 413
preconditionFailed412 :: Status #
Precondition Failed 412
Length Required 411
conflict409 :: Status #
Conflict 409
Request Timeout 408
proxyAuthenticationRequired407 :: Status #
Proxy Authentication Required 407
Not Acceptable 406
methodNotAllowed405 :: Status #
Method Not Allowed 405
notFound404 :: Status #
Not Found 404
forbidden403 :: Status #
Forbidden 403
paymentRequired402 :: Status #
Payment Required 402
Unauthorized 401
badRequest400 :: Status #
Bad Request 400
permanentRedirect308 :: Status #
Permanent Redirect 308
temporaryRedirect307 :: Status #
Temporary Redirect 307
useProxy305 :: Status #
Use Proxy 305
Not Modified 304
seeOther303 :: Status #
See Other 303
movedPermanently301 :: Status #
Moved Permanently 301
multipleChoices300 :: Status #
Multiple Choices 300
Partial Content 206
Reset Content 205
noContent204 :: Status #
No Content 204
nonAuthoritative203 :: Status #
Non-Authoritative Information 203
accepted202 :: Status #
Accepted 202
created201 :: Status #
Created 201
switchingProtocols101 :: Status #
Switching Protocols 101
continue100 :: Status #
Continue 100
mkStatus :: Int -> ByteString -> Status #
Create a Status from status code and message.
HTTP Status.
Only the statusCode
is used for comparisons.
Please use mkStatus
to create status codes from code and message, or the Enum
instance or the
status code constants (like ok200
). There might be additional record members in the future.
Note that the Show instance is only for debugging.
renderStdMethod :: StdMethod -> Method #
Convert a StdMethod
to a ByteString
.
renderMethod :: Either ByteString StdMethod -> Method #
Convert an algebraic method to a ByteString
.
parseMethod :: Method -> Either ByteString StdMethod #
Convert a method ByteString
to a StdMethod
if possible.
methodPatch :: Method #
HTTP Method constants.
methodOptions :: Method #
HTTP Method constants.
methodConnect :: Method #
HTTP Method constants.
methodTrace :: Method #
HTTP Method constants.
methodDelete :: Method #
HTTP Method constants.
methodHead :: Method #
HTTP Method constants.
methodPost :: Method #
HTTP Method constants.
type Method = ByteString #
HTTP method (flat string type).
HTTP standard method (as defined by RFC 2616, and PATCH which is defined by RFC 5789).
Instances
parseByteRanges :: ByteString -> Maybe ByteRanges #
Parse the value of a Range header into a ByteRanges
.
>>>
parseByteRanges "error"
Nothing>>>
parseByteRanges "bytes=0-499"
Just [ByteRangeFromTo 0 499]>>>
parseByteRanges "bytes=500-999"
Just [ByteRangeFromTo 500 999]>>>
parseByteRanges "bytes=-500"
Just [ByteRangeSuffix 500]>>>
parseByteRanges "bytes=9500-"
Just [ByteRangeFrom 9500]>>>
parseByteRanges "bytes=0-0,-1"
Just [ByteRangeFromTo 0 0,ByteRangeSuffix 1]>>>
parseByteRanges "bytes=500-600,601-999"
Just [ByteRangeFromTo 500 600,ByteRangeFromTo 601 999]>>>
parseByteRanges "bytes=500-700,601-999"
Just [ByteRangeFromTo 500 700,ByteRangeFromTo 601 999]
renderByteRange :: ByteRange -> ByteString #
hCookie :: HeaderName #
HTTP Header names according to https://tools.ietf.org/html/rfc6265#section-4
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hServer :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hReferer :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hRange :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hLocation :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfRange :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hIfModifiedSince :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hDate :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentLength :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hContentEncoding :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAuthorization :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAcceptLanguage :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
hAccept :: HeaderName #
HTTP Header names according to http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
type HeaderName = CI ByteString #
Header name
type RequestHeaders = [Header] #
Request Headers
type ResponseHeaders = [Header] #
Response Headers
RFC 2616 Byte range (individual).
Negative indices are not allowed!
Instances
Eq ByteRange | |
Data ByteRange | |
Defined in Network.HTTP.Types.Header gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ByteRange -> c ByteRange # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ByteRange # toConstr :: ByteRange -> Constr # dataTypeOf :: ByteRange -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ByteRange) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ByteRange) # gmapT :: (forall b. Data b => b -> b) -> ByteRange -> ByteRange # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ByteRange -> r # gmapQ :: (forall d. Data d => d -> u) -> ByteRange -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> ByteRange -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ByteRange -> m ByteRange # | |
Ord ByteRange | |
Defined in Network.HTTP.Types.Header | |
Show ByteRange | |
type ByteRanges = [ByteRange] #
RFC 2616 Byte ranges (set).
timed :: (MonadIO m, MonadMetrics m, MonadMask m) => Text -> m a -> m a #
Record the time of executing the given action in seconds. Defers to
timed'
.
- Since v0.1.0.0
timedList :: (MonadIO m, MonadMetrics m, MonadMask m) => Resolution -> [Text] -> m a -> m a #
Record the time taken to perform the action, under several names at once.
The number is stored in a Distribution
and is
converted to the specified Resolution
.
This is useful to store the same durations data sectioned by different criteria, e.g.:
timedList Seconds ["request.byUser." <> userName, "request.byType." <> requestType] $ do ...
So you will have "request.byUser.someuser"
storing duration distribution for requests
of user "someuser"
of any type; and "request.byType.sometype"
storing
duration distribution for requests of type "sometype"
from any user.
timed' :: (MonadIO m, MonadMetrics m, MonadMask m) => Resolution -> Text -> m a -> m a #
Record the time taken to perform the named action. The number is
stored in a Distribution
and is converted
to the specified Resolution
.
- Since v0.1.0.0
gauge :: (MonadIO m, MonadMetrics m) => Text -> Int -> m () #
A type specialized version of gauge'
to avoid ambiguous types.
- Since v0.1.0.0
gauge' :: (MonadIO m, MonadMetrics m, Integral int) => Text -> int -> m () #
Set the value of the named Gauge
.
- Since v0.1.0.0
distribution :: (MonadIO m, MonadMetrics m) => Text -> Double -> m () #
Add the value to the named Distribution
.
- Since v0.1.0.0
counter :: (MonadIO m, MonadMetrics m) => Text -> Int -> m () #
A type specialized version of counter'
to avoid ambiguous type
errors.
- Since v0.1.0.0
counter' :: (MonadIO m, MonadMetrics m, Integral int) => Text -> int -> m () #
Adds the value to the named Counter
.
- Since v0.1.0.0
increment :: (MonadIO m, MonadMetrics m) => Text -> m () #
Increment the named counter by 1.
- Since v0.1.0.0
class Monad m => MonadMetrics (m :: * -> *) where #
A type can be an instance of MonadMetrics
if it can provide a Metrics
somehow. Commonly, this will be implemented as a ReaderT
where some
field in the environment is the Metrics
data.
- Since v0.1.0.0
getMetrics :: m Metrics #
Instances
(Has ModMetrics α, Monad μ, MonadReader α μ) => MonadMetrics μ # | |
Defined in Magicbane.Has getMetrics :: μ Metrics # | |
(MonadMetrics m, MonadTrans t, Monad (t m)) => MonadMetrics (t m) | |
Defined in Control.Monad.Metrics getMetrics :: t m Metrics # | |
Monad m => MonadMetrics (ReaderT Metrics m) | |
Defined in Control.Monad.Metrics getMetrics :: ReaderT Metrics m Metrics # |
A container for metrics used by the MonadMetrics
class.
- Since v0.1.0.0
Instances
Monad m => MonadMetrics (ReaderT Metrics m) | |
Defined in Control.Monad.Metrics getMetrics :: ReaderT Metrics m Metrics # |
data Resolution #
A type representing the resolution of time to use for the timed
metric.
- Since v0.1.0.0
Instances
throwError :: MonadError e m => e -> m a #
Is used within a monadic computation to begin exception processing.
unreserved :: Char -> Bool #
parseabsoluteURI :: String -> Maybe URI #
normalizePathSegments :: String -> String #
Path segment normalization; cf. RFC3986 section 6.2.2.3
normalizeEscape :: String -> String #
Encoding normalization; cf. RFC3986 section 6.2.2.2
normalizeCase :: String -> String #
Case normalization; cf. RFC3986 section 6.2.2.1 NOTE: authority case normalization is not performed
relativeFrom :: URI -> URI -> URI #
Returns a new URI
which represents the relative location of
the first URI
with respect to the second URI
. Thus, the
values supplied are expected to be absolute URIs, and the result
returned may be a relative URI.
Example:
"http://example.com/Root/sub1/name2#frag" `relativeFrom` "http://example.com/Root/sub2/name2#frag" == "../sub1/name2#frag"
There is no single correct implementation of this function, but any acceptable implementation must satisfy the following:
(uabs `relativeFrom` ubase) `relativeTo` ubase == uabs
For any valid absolute URI. (cf. http://lists.w3.org/Archives/Public/uri/2003Jan/0008.html http://lists.w3.org/Archives/Public/uri/2003Jan/0005.html)
pathSegments :: URI -> [String] #
Returns the segments of the path component. E.g., pathSegments $ parseURI "http://example.org/foo/bar/baz" == ["foo", "bar", "baz"]
relativeTo :: URI -> URI -> URI #
nonStrictRelativeTo :: URI -> URI -> URI #
unEscapeString :: String -> String #
Turns all instances of escaped characters in the string back into literal characters.
:: (Char -> Bool) | a predicate which returns |
-> String | the string to process |
-> String | the resulting URI string |
Can be used to make a string valid for use in a URI.
escapeURIChar :: (Char -> Bool) -> Char -> String #
Escape character if supplied predicate is not satisfied, otherwise return character as singleton string.
isUnescapedInURIComponent :: Char -> Bool #
Returns True
if the character is allowed unescaped in a URI component.
>>>
escapeURIString isUnescapedInURIComponent "http://haskell.org:80?some_param=true&other_param=їґ"
"http%3A%2F%2Fhaskell.org%3A80%3Fsome_param%3Dtrue%26other_param%3D%D1%97%D2%91"
isUnescapedInURI :: Char -> Bool #
Returns True
if the character is allowed unescaped in a URI.
>>>
escapeURIString isUnescapedInURI "http://haskell.org:80?some_param=true&other_param=їґ"
"http://haskell.org:80?some_param=true&other_param=%D1%97%D2%91"
isAllowedInURI :: Char -> Bool #
Returns True
if the character is allowed in a URI.
uriToString :: (String -> String) -> URI -> ShowS #
Turn a URI
into a string.
Uses a supplied function to map the userinfo part of the URI.
The Show instance for URI uses a mapping that hides any password
that may be present in the URI. Use this function with argument id
to preserve the password in the formatted output.
isUnreserved :: Char -> Bool #
Returns True
if the character is an "unreserved" character in
a URI. These characters do not need to be escaped in a URI. The
only characters allowed in a URI are either "reserved",
"unreserved", or an escape sequence (%
followed by two hex digits).
isReserved :: Char -> Bool #
Returns True
if the character is a "reserved" character in a
URI. To include a literal instance of one of these characters in a
component of a URI, it must be escaped.
uriIsRelative :: URI -> Bool #
uriIsAbsolute :: URI -> Bool #
isIPv4address :: String -> Bool #
Test if string contains a valid IPv4 address
isIPv6address :: String -> Bool #
Test if string contains a valid IPv6 address
isAbsoluteURI :: String -> Bool #
Test if string contains a valid absolute URI (an absolute URI without a fragment identifier).
isRelativeReference :: String -> Bool #
Test if string contains a valid relative URI (a relative URI with optional fragment identifier).
isURIReference :: String -> Bool #
Test if string contains a valid URI reference (an absolute or relative URI with optional fragment identifier).
Test if string contains a valid URI (an absolute URI with optional fragment identifier).
parseAbsoluteURI :: String -> Maybe URI #
parseRelativeReference :: String -> Maybe URI #
parseURIReference :: String -> Maybe URI #
parseURI :: String -> Maybe URI #
Turn a string containing a URI into a URI
.
Returns Nothing
if the string is not a valid URI;
(an absolute URI with optional fragment identifier).
NOTE: this is different from the previous network.URI,
whose parseURI
function works like parseURIReference
in this module.
Type for authority value within a URI
URIAuth | |
|
Instances
Eq URIAuth | |
Data URIAuth | |
Defined in Network.URI gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> URIAuth -> c URIAuth # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c URIAuth # toConstr :: URIAuth -> Constr # dataTypeOf :: URIAuth -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c URIAuth) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c URIAuth) # gmapT :: (forall b. Data b => b -> b) -> URIAuth -> URIAuth # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> URIAuth -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> URIAuth -> r # gmapQ :: (forall d. Data d => d -> u) -> URIAuth -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> URIAuth -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> URIAuth -> m URIAuth # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> URIAuth -> m URIAuth # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> URIAuth -> m URIAuth # | |
Ord URIAuth | |
Show URIAuth | |
NFData URIAuth | |
Defined in Network.URI |
rQ :: QuasiQuoter #
A variant of r
that interprets the "|~]"
sequence as "|]"
,
"|~~]"
as "|~]"
and, in general, "|~^n]"
as "|~^(n-1)]"
for n >= 1.
Usage:
ghci> [rQ||~]|~]|] "|]|]" ghci> [rQ||~~]|] "|~]" ghci> [rQ||~~~~]|] "|~~~]"
r :: QuasiQuoter #
A quasiquoter for raw string literals - that is, string literals that don't
recognise the standard escape sequences (such as '\n'
). Basically, they
make your code more readable by freeing you from the responsibility to escape
backslashes. They are useful when working with regular expressions, DOS/Windows
paths and markup languages (such as XML).
Don't forget the LANGUAGE QuasiQuotes
pragma if you're using this
module in your code.
Usage:
ghci> :set -XQuasiQuotes ghci> import Text.RawString.QQ ghci> let s = [r|\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}|] ghci> s "\\w+@[a-zA-Z_]+?\\.[a-zA-Z]{2,3}" ghci> [r|C:\Windows\SYSTEM|] ++ [r|\user32.dll|] "C:\\Windows\\SYSTEM\\user32.dll"
Multiline raw string literals are also supported:
multiline :: String multiline = [r|<HTML> <HEAD> <TITLE>Auto-generated html formated source</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252"> </HEAD> <BODY LINK="800080" BGCOLOR="#ffffff"> <P> </P> <PRE>|]
Caveat: since the "|]"
character sequence is used to terminate the
quasiquotation, you can't use it inside the raw string literal. Use rQ
if you
want to embed that character sequence inside the raw string.
For more on raw strings, see e.g. http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2053.html
For more on quasiquotation, see http://www.haskell.org/haskellwiki/Quasiquotation
:: Monad m | |
=> TypeRep | The |
-> Doc Void | A |
-> RefineT m a |
A handler for a
.RefineException
throwRefineOtherException
is useful for defining what
behaviour validate
should have in the event of a predicate failure.
catchRefine :: Monad m => RefineT m a -> (RefineException -> RefineT m a) -> RefineT m a #
A handler function to handle previous
s
and return to normal execution. A common idiom is:RefineException
do { action1; action2; action3 } `catchRefine'
handler
where the action functions can call
. Note that
handler and the do-block must have the same return type.throwRefine
throwRefine :: Monad m => RefineException -> RefineT m a #
One can use
inside of a monadic
context to begin processing a throwRefine
.RefineException
runRefineM :: RefineM a -> Either RefineException a #
Run a monadic action of type
,
yielding an RefineM
a
.Either
RefineException
a
This is just defined as
.runIdentity
.
runRefineT
refineM :: Either RefineException a -> RefineM a #
Constructs a computation in the RefineM
monad. (The inverse of
).runRefineM
mapRefineT :: (m (Either RefineException a) -> n (Either RefineException b)) -> RefineT m a -> RefineT n b #
Map the unwrapped computation using the given function.
runRefineT
(mapRefineT
f m) = f (runRefineT
m)
runRefineT :: RefineT m a -> m (Either RefineException a) #
The inverse of
.RefineT
displayRefineException :: RefineException -> Doc ann #
Display a RefineException
as a Doc
ann
rightOr :: Refined r x -> Refined (Or l r) x #
This function helps type inference. It is equivalent to the following:
instance Weaken r (Or l r)
leftOr :: Refined l x -> Refined (Or l r) x #
This function helps type inference. It is equivalent to the following:
instance Weaken l (Or l r)
andRight :: Refined (And l r) x -> Refined r x #
This function helps type inference. It is equivalent to the following:
instance Weaken (And l r) r
andLeft :: Refined (And l r) x -> Refined l x #
This function helps type inference. It is equivalent to the following:
instance Weaken (And l r) l
refineTH :: (Predicate p x, Lift x) => x -> Q (TExp (Refined p x)) #
Constructs a Refined
value at compile-time using -XTemplateHaskell
.
For example:
>>>
$$(refineTH 23) :: Refined Positive Int
Refined 23
Here's an example of an invalid value:
>>>
$$(refineTH 0) :: Refined Positive Int
<interactive>:6:4: Value is not greater than 0 In the Template Haskell splice $$(refineTH 0) In the expression: $$(refineTH 0) :: Refined Positive Int In an equation for ‘it’: it = $$(refineTH 0) :: Refined Positive Int
If it's not evident, the example above indicates a compile-time failure, which means that the checking was done at compile-time, thus introducing a zero runtime overhead compared to a plain value construction.
unsafeRefine :: Predicate p x => x -> Refined p x #
refineError :: (Predicate p x, MonadError RefineException m) => x -> m (Refined p x) #
Constructs a Refined
value at run-time,
calling throwError
if the value
does not satisfy the predicate.
refineFail :: (Predicate p x, MonadFail m) => x -> m (Refined p x) #
refineThrow :: (Predicate p x, MonadThrow m) => x -> m (Refined p x) #
refine :: Predicate p x => x -> Either RefineException (Refined p x) #
A smart constructor of a Refined
value.
Checks the input value at runtime.
A refinement type, which wraps a value of type x
,
ensuring that it satisfies a type-level predicate p
.
The only ways that this library provides to construct
a value of type Refined
are with the 'refine-' family
of functions, because the use of the newtype constructor
gets around the checking of the predicate. This restriction
on the user makes unrefine
safe.
If you would really like to
construct a Refined
value without checking the predicate,
use unsafeCoerce
.
Instances
Foldable (Refined p) | |
Defined in Refined fold :: Monoid m => Refined p m -> m # foldMap :: Monoid m => (a -> m) -> Refined p a -> m # foldr :: (a -> b -> b) -> b -> Refined p a -> b # foldr' :: (a -> b -> b) -> b -> Refined p a -> b # foldl :: (b -> a -> b) -> b -> Refined p a -> b # foldl' :: (b -> a -> b) -> b -> Refined p a -> b # foldr1 :: (a -> a -> a) -> Refined p a -> a # foldl1 :: (a -> a -> a) -> Refined p a -> a # toList :: Refined p a -> [a] # length :: Refined p a -> Int # elem :: Eq a => a -> Refined p a -> Bool # maximum :: Ord a => Refined p a -> a # minimum :: Ord a => Refined p a -> a # | |
Eq x => Eq (Refined p x) | |
Ord x => Ord (Refined p x) | |
(Read x, Predicate p x) => Read (Refined p x) | |
Show x => Show (Refined p x) | |
Lift x => Lift (Refined p x) | |
ToJSON α => ToJSON (Refined ρ α) # | |
Defined in Magicbane.Validation | |
(FromJSON α, Predicate ρ α) => FromJSON (Refined ρ α) # | |
class Typeable p => Predicate p x where #
A typeclass which defines a runtime interpretation of
a type-level predicate p
for type x
.
validate :: Monad m => p -> x -> RefineT m () #
Check the value x
according to the predicate p
,
producing an error string if the value does not satisfy.
Instances
(IsList t, Ord (Item t)) => Predicate Ascending t | |
(IsList t, Ord (Item t)) => Predicate Descending t | |
(Predicate p x, Typeable p) => Predicate (Not p) x | |
(Ord x, Num x, KnownNat n) => Predicate (LessThan n) x | |
(Ord x, Num x, KnownNat n) => Predicate (GreaterThan n) x | |
(Ord x, Num x, KnownNat n) => Predicate (From n) x | |
(Ord x, Num x, KnownNat n) => Predicate (To n) x | |
(Eq x, Num x, KnownNat n) => Predicate (EqualTo n) x | |
(Eq x, Num x, KnownNat n) => Predicate (NotEqualTo n) x | |
(Foldable t, KnownNat n) => Predicate (SizeLessThan n) (t a) | |
(Foldable t, KnownNat n) => Predicate (SizeGreaterThan n) (t a) | |
(Foldable t, KnownNat n) => Predicate (SizeEqualTo n) (t a) | |
(Predicate l x, Predicate r x, Typeable l, Typeable r) => Predicate (And l r) x | |
(Predicate l x, Predicate r x, Typeable l, Typeable r) => Predicate (Or l r) x | |
(Ord x, Num x, KnownNat mn, KnownNat mx, mn <= mx) => Predicate (FromTo mn mx) x | |
The negation of a predicate.
The conjunction of two predicates.
The disjunction of two predicates.
data SizeLessThan (n :: Nat) #
A Predicate
ensuring that the Foldable
has a length
which is less than the specified type-level number.
Instances
(Foldable t, KnownNat n) => Predicate (SizeLessThan n) (t a) | |
data SizeGreaterThan (n :: Nat) #
A Predicate
ensuring that the Foldable
has a length
which is greater than the specified type-level number.
Instances
(Foldable t, KnownNat n) => Predicate (SizeGreaterThan n) (t a) | |
data SizeEqualTo (n :: Nat) #
A Predicate
ensuring that the Foldable
has a length
which is equal to the specified type-level number.
Instances
(Foldable t, KnownNat n) => Predicate (SizeEqualTo n) (t a) | |
data Descending #
A Predicate
ensuring that the value is less than the
specified type-level number.
data GreaterThan (n :: Nat) #
A Predicate
ensuring that the value is greater than the
specified type-level number.
Instances
(Ord x, Num x, KnownNat n) => Predicate (GreaterThan n) x | |
m <= n => Weaken (GreaterThan n) (GreaterThan m) | |
Defined in Refined weaken :: Refined (GreaterThan n) x -> Refined (GreaterThan m) x # | |
m <= n => Weaken (GreaterThan n) (From m) | |
A Predicate
ensuring that the value is greater than or equal to the
specified type-level number.
A Predicate
ensuring that the value is less than or equal to the
specified type-level number.
data FromTo (mn :: Nat) (mx :: Nat) #
A Predicate
ensuring that the value is within an inclusive range.
A Predicate
ensuring that the value is equal to the specified
type-level number n
.
data NotEqualTo (n :: Nat) #
A Predicate
ensuring that the value is not equal to the specified
type-level number n
.
type Positive = GreaterThan 0 #
A Predicate
ensuring that the value is greater than zero.
type NonPositive = To 0 #
A Predicate
ensuring that the value is less than or equal to zero.
type NonNegative = From 0 #
A Predicate
ensuring that the value is greater than or equal to zero.
type NonZero = NotEqualTo 0 #
A Predicate
ensuring that the value is not equal to zero.
type NonEmpty = SizeGreaterThan 0 #
A typeclass containing "safe" conversions between refined predicates where the target is weaker than the source: that is, all values that satisfy the first predicate will be guarunteed to satisy the second.
Take care: writing an instance declaration for your custom predicates is
the same as an assertion that weaken
is safe to use:
instance Weaken
Pred1 Pred2
For most of the instances, explicit type annotations for the result value's type might be required.
Instances
n <= m => Weaken (LessThan n) (To m) | |
n <= m => Weaken (LessThan n) (LessThan m) | |
m <= n => Weaken (GreaterThan n) (GreaterThan m) | |
Defined in Refined weaken :: Refined (GreaterThan n) x -> Refined (GreaterThan m) x # | |
m <= n => Weaken (GreaterThan n) (From m) | |
m <= n => Weaken (From n) (From m) | |
n <= m => Weaken (To n) (To m) | |
m <= q => Weaken (FromTo n m) (To q) | |
p <= n => Weaken (FromTo n m) (From p) | |
(p <= n, m <= q) => Weaken (FromTo n m) (FromTo p q) | |
data RefineException #
An exception encoding the way in which a Predicate
failed.
RefineNotException !TypeRep | A |
RefineAndException !TypeRep !(These RefineException RefineException) | A |
RefineOrException !TypeRep !RefineException !RefineException | A |
RefineOtherException !TypeRep !(Doc Void) | A |
Instances
data RefineT (m :: * -> *) a #
A monad transformer that adds
s to other monads.RefineException
The
and pure
functions yield computations that produce
the given value, while return
sequences two subcomputations, exiting
on the first >>=
.RefineException
Instances
MonadTrans RefineT | |
Monad m => MonadError RefineException (RefineT m) | |
Defined in Refined throwError :: RefineException -> RefineT m a # catchError :: RefineT m a -> (RefineException -> RefineT m a) -> RefineT m a # | |
Monad m => Monad (RefineT m) | |
Functor m => Functor (RefineT m) | |
MonadFix m => MonadFix (RefineT m) | |
Monad m => Applicative (RefineT m) | |
Generic1 (RefineT m :: * -> *) | |
Generic (RefineT m a) | |
type Rep1 (RefineT m :: * -> *) | |
Defined in Refined | |
type Rep (RefineT m a) | |
getChanContents :: MonadIO m => Chan a -> m [a] #
Lifted getChanContents
.
Since: unliftio-0.1.0.0
writeList2Chan :: MonadIO m => Chan a -> [a] -> m () #
Lifted writeList2Chan
.
Since: unliftio-0.1.0.0
data StringException #
Exception type thrown by throwString
.
Note that the second field of the data constructor depends on GHC/base version. For base 4.9 and GHC 8.0 and later, the second field is a call stack. Previous versions of GHC and base do not support call stacks, and the field is simply unit (provided to make pattern matching across GHC versions easier).
Since: unliftio-0.1.0.0
Instances
Show StringException | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Exception showsPrec :: Int -> StringException -> ShowS # show :: StringException -> String # showList :: [StringException] -> ShowS # | |
Exception StringException | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Exception |
data AsyncExceptionWrapper where #
Wrap up a synchronous exception to be treated as an asynchronous exception.
This is intended to be created via toAsyncException
.
Since: unliftio-0.1.0.0
Instances
Show AsyncExceptionWrapper | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Exception showsPrec :: Int -> AsyncExceptionWrapper -> ShowS # show :: AsyncExceptionWrapper -> String # showList :: [AsyncExceptionWrapper] -> ShowS # | |
Exception AsyncExceptionWrapper | Since: unliftio-0.1.0.0 |
data SyncExceptionWrapper where #
Wrap up an asynchronous exception to be treated as a synchronous exception.
This is intended to be created via toSyncException
.
Since: unliftio-0.1.0.0
Instances
Show SyncExceptionWrapper | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Exception showsPrec :: Int -> SyncExceptionWrapper -> ShowS # show :: SyncExceptionWrapper -> String # showList :: [SyncExceptionWrapper] -> ShowS # | |
Exception SyncExceptionWrapper | Since: unliftio-0.1.0.0 |
Defined in UnliftIO.Exception |
catch :: (MonadUnliftIO m, Exception e) => m a -> (e -> m a) -> m a #
Unlifted catch
, but will not catch asynchronous exceptions.
Since: unliftio-0.1.0.0
catchIO :: MonadUnliftIO m => m a -> (IOException -> m a) -> m a #
catch
specialized to only catching IOException
s.
Since: unliftio-0.1.0.0
catchAny :: MonadUnliftIO m => m a -> (SomeException -> m a) -> m a #
catch
specialized to catch all synchronous exception.
Since: unliftio-0.1.0.0
catchDeep :: (MonadUnliftIO m, Exception e, NFData a) => m a -> (e -> m a) -> m a #
Same as catch
, but fully force evaluation of the result value
to find all impure exceptions.
Since: unliftio-0.1.0.0
catchAnyDeep :: (NFData a, MonadUnliftIO m) => m a -> (SomeException -> m a) -> m a #
catchDeep
specialized to catch all synchronous exception.
Since: unliftio-0.1.0.0
catchJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> m a -> (b -> m a) -> m a #
handle :: (MonadUnliftIO m, Exception e) => (e -> m a) -> m a -> m a #
Flipped version of catch
.
Since: unliftio-0.1.0.0
handleIO :: MonadUnliftIO m => (IOException -> m a) -> m a -> m a #
handle
specialized to only catching IOException
s.
Since: unliftio-0.1.0.0
handleAny :: MonadUnliftIO m => (SomeException -> m a) -> m a -> m a #
Flipped version of catchAny
.
Since: unliftio-0.1.0.0
handleDeep :: (MonadUnliftIO m, Exception e, NFData a) => (e -> m a) -> m a -> m a #
Flipped version of catchDeep
.
Since: unliftio-0.1.0.0
handleAnyDeep :: (MonadUnliftIO m, NFData a) => (SomeException -> m a) -> m a -> m a #
Flipped version of catchAnyDeep
.
Since: unliftio-0.1.0.0
handleJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> (b -> m a) -> m a -> m a #
Flipped catchJust
.
Since: unliftio-0.1.0.0
try :: (MonadUnliftIO m, Exception e) => m a -> m (Either e a) #
Unlifted try
, but will not catch asynchronous exceptions.
Since: unliftio-0.1.0.0
tryIO :: MonadUnliftIO m => m a -> m (Either IOException a) #
try
specialized to only catching IOException
s.
Since: unliftio-0.1.0.0
tryAny :: MonadUnliftIO m => m a -> m (Either SomeException a) #
try
specialized to catch all synchronous exceptions.
Since: unliftio-0.1.0.0
tryDeep :: (MonadUnliftIO m, Exception e, NFData a) => m a -> m (Either e a) #
Same as try
, but fully force evaluation of the result value
to find all impure exceptions.
Since: unliftio-0.1.0.0
tryAnyDeep :: (MonadUnliftIO m, NFData a) => m a -> m (Either SomeException a) #
tryDeep
specialized to catch all synchronous exceptions.
Since: unliftio-0.1.0.0
tryJust :: (MonadUnliftIO m, Exception e) => (e -> Maybe b) -> m a -> m (Either b a) #
A variant of try
that takes an exception predicate to select
which exceptions are caught.
Since: unliftio-0.1.0.0
pureTry :: a -> Either SomeException a #
Evaluate the value to WHNF and catch any synchronous exceptions.
The expression may still have bottom values within it; you may
instead want to use pureTryDeep
.
Since: unliftio-0.2.2.0
pureTryDeep :: NFData a => a -> Either SomeException a #
Evaluate the value to NF and catch any synchronous exceptions.
Since: unliftio-0.2.2.0
catches :: MonadUnliftIO m => m a -> [Handler m a] -> m a #
Same as upstream catches
, but will not catch
asynchronous exceptions.
Since: unliftio-0.1.0.0
catchesDeep :: (MonadUnliftIO m, NFData a) => m a -> [Handler m a] -> m a #
Same as catches
, but fully force evaluation of the result value
to find all impure exceptions.
Since: unliftio-0.1.0.0
evaluateDeep :: (MonadIO m, NFData a) => a -> m a #
bracket :: MonadUnliftIO m => m a -> (a -> m b) -> (a -> m c) -> m c #
Async safe version of bracket
.
Since: unliftio-0.1.0.0
bracket_ :: MonadUnliftIO m => m a -> m b -> m c -> m c #
Async safe version of bracket_
.
Since: unliftio-0.1.0.0
bracketOnError :: MonadUnliftIO m => m a -> (a -> m b) -> (a -> m c) -> m c #
Async safe version of bracketOnError
.
Since: unliftio-0.1.0.0
bracketOnError_ :: MonadUnliftIO m => m a -> m b -> m c -> m c #
A variant of bracketOnError
where the return value from the first
computation is not required.
Since: unliftio-0.1.0.0
finally :: MonadUnliftIO m => m a -> m b -> m a #
Async safe version of finally
.
Since: unliftio-0.1.0.0
withException :: (MonadUnliftIO m, Exception e) => m a -> (e -> m b) -> m a #
Like onException
, but provides the handler the thrown
exception.
Since: unliftio-0.1.0.0
onException :: MonadUnliftIO m => m a -> m b -> m a #
Async safe version of onException
.
Since: unliftio-0.1.0.0
throwIO :: (MonadIO m, Exception e) => e -> m a #
Synchronously throw the given exception.
Since: unliftio-0.1.0.0
toSyncException :: Exception e => e -> SomeException #
Convert an exception into a synchronous exception.
For synchronous exceptions, this is the same as toException
.
For asynchronous exceptions, this will wrap up the exception with
SyncExceptionWrapper
.
Since: unliftio-0.1.0.0
toAsyncException :: Exception e => e -> SomeException #
Convert an exception into an asynchronous exception.
For asynchronous exceptions, this is the same as toException
.
For synchronous exceptions, this will wrap up the exception with
AsyncExceptionWrapper
.
Since: unliftio-0.1.0.0
isSyncException :: Exception e => e -> Bool #
Check if the given exception is synchronous.
Since: unliftio-0.1.0.0
isAsyncException :: Exception e => e -> Bool #
Check if the given exception is asynchronous.
Since: unliftio-0.1.0.0
mask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m b) -> m b #
Unlifted version of mask
.
Since: unliftio-0.1.0.0
uninterruptibleMask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m b) -> m b #
Unlifted version of uninterruptibleMask
.
Since: unliftio-0.1.0.0
mask_ :: MonadUnliftIO m => m a -> m a #
Unlifted version of mask_
.
Since: unliftio-0.1.0.0
uninterruptibleMask_ :: MonadUnliftIO m => m a -> m a #
Unlifted version of uninterruptibleMask_
.
Since: unliftio-0.1.0.0
throwString :: (MonadIO m, HasCallStack) => String -> m a #
A convenience function for throwing a user error. This is useful for cases where it would be too high a burden to define your own exception type.
This throws an exception of type StringException
. When GHC
supports it (base 4.9 and GHC 8.0 and onward), it includes a call
stack.
Since: unliftio-0.1.0.0
stringException :: HasCallStack -> String -> StringException #
Smart constructor for a StringException
that deals with the
call stack.
Since: unliftio-0.1.0.0
throwTo :: (Exception e, MonadIO m) => ThreadId -> e -> m () #
Throw an asynchronous exception to another thread.
Synchronously typed exceptions will be wrapped into an
AsyncExceptionWrapper
, see
https://github.com/fpco/safe-exceptions#determining-sync-vs-async.
It's usually a better idea to use the UnliftIO.Async module, see https://github.com/fpco/safe-exceptions#quickstart.
Since: unliftio-0.1.0.0
impureThrow :: Exception e => e -> a #
Generate a pure value which, when forced, will synchronously throw the given exception.
Generally it's better to avoid using this function and instead use throwIO
,
see https://github.com/fpco/safe-exceptions#quickstart.
Since: unliftio-0.1.0.0
fromEither :: (Exception e, MonadIO m) => Either e a -> m a #
fromEitherIO :: (Exception e, MonadIO m) => IO (Either e a) -> m a #
Same as fromEither
, but works on an IO
-wrapped Either
.
Since: unliftio-0.1.0.0
fromEitherM :: (Exception e, MonadIO m) => m (Either e a) -> m a #
Same as fromEither
, but works on an m
-wrapped Either
.
Since: unliftio-0.1.0.0
newEmptyMVar :: MonadIO m => m (MVar a) #
Lifted newEmptyMVar
.
Since: unliftio-0.1.0.0
tryTakeMVar :: MonadIO m => MVar a -> m (Maybe a) #
Lifted tryTakeMVar
.
Since: unliftio-0.1.0.0
tryPutMVar :: MonadIO m => MVar a -> a -> m Bool #
Lifted tryPutMVar
.
Since: unliftio-0.1.0.0
isEmptyMVar :: MonadIO m => MVar a -> m Bool #
Lifted isEmptyMVar
.
Since: unliftio-0.1.0.0
tryReadMVar :: MonadIO m => MVar a -> m (Maybe a) #
Lifted tryReadMVar
.
Since: unliftio-0.1.0.0
withMVar :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b #
Unlifted withMVar
.
Since: unliftio-0.1.0.0
withMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m b) -> m b #
Unlifted withMVarMasked
.
Since: unliftio-0.1.0.0
modifyMVar_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m () #
Unlifted modifyMVar_
.
Since: unliftio-0.1.0.0
modifyMVar :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b #
Unlifted modifyMVar
.
Since: unliftio-0.1.0.0
modifyMVarMasked_ :: MonadUnliftIO m => MVar a -> (a -> m a) -> m () #
Unlifted modifyMVarMasked_
.
Since: unliftio-0.1.0.0
modifyMVarMasked :: MonadUnliftIO m => MVar a -> (a -> m (a, b)) -> m b #
Unlifted modifyMVarMasked
.
Since: unliftio-0.1.0.0
mkWeakMVar :: MonadUnliftIO m => MVar a -> m () -> m (Weak (MVar a)) #
Unlifted mkWeakMVar
.
Since: unliftio-0.1.0.0
The Reader+IO monad. This is different from a ReaderT
because:
- It's not a transformer, it hardcodes IO for simpler usage and error messages.
- Instances of typeclasses like
MonadLogger
are implemented using classes defined on the environment, instead of using an underlying monad.
Instances
MonadReader env (RIO env) | |
HasStateRef s env => MonadState s (RIO env) | |
(Monoid w, HasWriteRef w env) => MonadWriter w (RIO env) | |
Monad (RIO env) | |
Functor (RIO env) | |
Applicative (RIO env) | |
MonadIO (RIO env) | |
Defined in RIO.Prelude.RIO | |
MonadUnliftIO (RIO env) | |
Defined in RIO.Prelude.RIO | |
PrimMonad (RIO env) | |
MonadThrow (RIO env) | |
Defined in RIO.Prelude.RIO | |
type PrimState (RIO env) | |
Defined in RIO.Prelude.RIO | |
type StM (RIO env) a | |
Defined in RIO.Orphans |
myThreadId :: MonadIO m => m ThreadId #
Lifted version of myThreadId
.
Since: unliftio-0.1.1.0
threadDelay :: MonadIO m => Int -> m () #
Lifted version of threadDelay
.
Since: unliftio-0.1.1.0
threadWaitRead :: MonadIO m => Fd -> m () #
Lifted version of threadWaitRead
.
Since: unliftio-0.1.1.0
threadWaitWrite :: MonadIO m => Fd -> m () #
Lifted version of threadWaitWrite
.
Since: unliftio-0.1.1.0
isCurrentThreadBound :: MonadIO m => m Bool #
Lifted version of isCurrentThreadBound
.
Since: unliftio-0.1.1.0
allFieldLinks' :: (HasLink (ToServantApi routes), GenericServant routes (AsLink a), ToServant routes (AsLink a) ~ MkLink (ToServantApi routes) a) => (Link -> a) -> routes (AsLink a) #
More general version of allFieldLinks
.
Since: servant-0.14.1
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.
Since: servant-0.14.1
fieldLink' :: (IsElem endpoint (ToServantApi routes), HasLink endpoint, GenericServant routes AsApi) => (Link -> a) -> (routes AsApi -> endpoint) -> MkLink endpoint a #
More general version of fieldLink
Since: servant-0.14.1
fieldLink :: (IsElem endpoint (ToServantApi routes), HasLink endpoint, GenericServant routes AsApi) => (routes AsApi -> endpoint) -> MkLink endpoint Link #
Given an API record field, create a link for that route. Only the field's type is used.
data Record route = Record { _get :: route :- Capture "id" Int :> Get '[JSON] String , _put :: route :- ReqBody '[JSON] Int :> Put '[JSON] Bool } deriving (Generic
) getLink :: Int -> Link getLink =fieldLink
_get
Since: servant-0.14.1
allLinks :: HasLink api => Proxy api -> MkLink api Link #
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] Double
>>>
let fooLink :<|> barLink = allLinks (Proxy :: Proxy API)
>>>
:t fooLink
fooLink :: Text -> Link>>>
:t barLink
barLink :: 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)) Link
MkLink (Capture "nest" Char :> (Capture "x" Int :> Get '[JSON] Int :<|> Capture "y" Double :> Get '[JSON] Double)) Link :: * = Char -> (Int -> Link) :<|> (Double -> Link)
:: (IsElem endpoint api, HasLink endpoint) | |
=> (Link -> a) | |
-> Proxy api | The whole API that this endpoint is a part of |
-> Proxy endpoint | The API endpoint you would like to point to |
-> MkLink endpoint a |
More general safeLink
.
:: (IsElem endpoint api, HasLink endpoint) | |
=> Proxy api | The whole API that this endpoint is a part of |
-> Proxy endpoint | The API endpoint you would like to point to |
-> MkLink endpoint Link |
Create a valid (by construction) relative URI with query params.
This function will only typecheck if endpoint
is part of the API api
linkURI' :: LinkArrayElementStyle -> Link -> URI #
Configurable linkURI
.
>>>
type API = "sum" :> QueryParams "x" Int :> Get '[JSON] Int
>>>
linkURI' 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
>>>
type API = "something" :> Get '[JSON] Int
>>>
linkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API)
something
>>>
type API = "sum" :> QueryParams "x" Int :> Get '[JSON] Int
>>>
linkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API) [1, 2, 3]
sum?x[]=1&x[]=2&x[]=3
>>>
type API = "foo/bar" :> Get '[JSON] Int
>>>
linkURI $ safeLink (Proxy :: Proxy API) (Proxy :: Proxy API)
foo%2Fbar
>>>
type SomeRoute = "abc" :> Capture "email" String :> Put '[JSON] ()
>>>
let someRoute = Proxy :: Proxy SomeRoute
>>>
safeLink someRoute someRoute "test@example.com"
Link {_segments = ["abc","test%40example.com"], _queryParams = []}
>>>
linkURI $ safeLink someRoute someRoute "test@example.com"
abc/test%40example.com
linkQueryParams :: Link -> [Param] #
linkSegments :: Link -> [String] #
A safe link datatype.
The only way of constructing a Link
is using safeLink
, which means any
Link
is guaranteed to be part of the mentioned API.
Instances
Show Link | |
ToHttpApiData Link | |
Defined in Servant.Links toUrlPiece :: Link -> Text # toEncodedUrlPiece :: Link -> Builder # toHeader :: Link -> ByteString # toQueryParam :: Link -> Text # |
Query parameter.
data LinkArrayElementStyle #
How to encode array query elements.
LinkArrayElementBracket | foo[]=1&foo[]=2 |
LinkArrayElementPlain | foo=1&foo=2 |
Instances
A type that specifies that an API record contains a set of links.
Since: servant-0.14.1
Instances
GenericMode (AsLink a) | |
Defined in Servant.Links | |
type (AsLink a) :- api | |
Defined in Servant.Links |
class HasLink (endpoint :: k) where #
Construct a toLink for an endpoint.
Instances
data WithNamedContext (name :: Symbol) (subContext :: [*]) subApi #
WithNamedContext
names a specific tagged context to use for the
combinators in the API. (See also in servant-server
,
Servant.Server.Context
.) For example:
type UseNamedContextAPI = WithNamedContext "myContext" '[String] ( ReqBody '[JSON] Int :> Get '[JSON] Int)
Both the ReqBody
and Get
combinators will use the WithNamedContext
with
type tag "myContext" as their context.
Context
s are only relevant for servant-server
.
For more information, see the tutorial.
Instances
HasLink sub => HasLink (WithNamedContext name context sub :: *) | |
Defined in Servant.Links type MkLink (WithNamedContext name context sub) a :: * # toLink :: (Link -> a) -> Proxy (WithNamedContext name context sub) -> Link -> MkLink (WithNamedContext name context sub) a # | |
(HasContextEntry context (NamedContext name subContext), HasServer subApi subContext) => HasServer (WithNamedContext name subContext subApi :: *) context | |
Defined in Servant.Server.Internal type ServerT (WithNamedContext name subContext subApi) m :: * # route :: Proxy (WithNamedContext name subContext subApi) -> Context context -> Delayed env (Server (WithNamedContext name subContext subApi)) -> Router env # hoistServerWithContext :: Proxy (WithNamedContext name subContext subApi) -> Proxy context -> (forall x. m x -> n x) -> ServerT (WithNamedContext name subContext subApi) m -> ServerT (WithNamedContext name subContext subApi) n # | |
type MkLink (WithNamedContext name context sub :: *) a | |
Defined in Servant.Links | |
type ServerT (WithNamedContext name subContext subApi :: *) m | |
Defined in Servant.Server.Internal |
type family Endpoints api :: [*] where ... #
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
type family IsElem' a s :: Constraint #
You may use this type family to tell the type checker that your custom
type may be skipped as part of a link. This is useful for things like
that are optional in a URI and do not affect them if they are
omitted.QueryParam
>>>
data CustomThing
>>>
type instance IsElem' e (CustomThing :> s) = IsElem e s
Note that
is called, which will mutually recurse back to IsElem
if it exhausts all other options again.IsElem'
Once you have written a HasLink
instance for CustomThing
you are ready to go.
type family IsElem endpoint api :: Constraint where ... #
Closed type family, check if endpoint
is within api
.
Uses
if it exhausts all other options.IsElem'
>>>
ok (Proxy :: Proxy (IsElem ("hello" :> Get '[JSON] Int) SampleAPI))
OK
>>>
ok (Proxy :: Proxy (IsElem ("bye" :> Get '[JSON] Int) SampleAPI))
... ... Could not deduce... ...
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 bya
would match the URL represented byb
, *not* whether a request represented bya
matches the endpoints servingb
(for the latter, useIsIn
).
IsElem e (sa :<|> sb) = Or (IsElem e sa) (IsElem e sb) | |
IsElem (e :> sa) (e :> sb) = IsElem sa sb | |
IsElem sa (Header sym x :> sb) = IsElem sa sb | |
IsElem sa (ReqBody y x :> sb) = IsElem sa sb | |
IsElem (CaptureAll z y :> sa) (CaptureAll x y :> sb) = IsElem sa sb | |
IsElem (Capture z y :> sa) (Capture x y :> sb) = IsElem sa sb | |
IsElem sa (QueryParam x y :> sb) = IsElem sa sb | |
IsElem sa (QueryParams x y :> sb) = IsElem sa sb | |
IsElem sa (QueryFlag x :> sb) = IsElem sa sb | |
IsElem (Verb m s ct typ) (Verb m s ct' typ) = IsSubList ct ct' | |
IsElem e e = () | |
IsElem e a = IsElem' e a |
type family IsSubAPI sub api :: Constraint where ... #
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 deduce... ...
This uses IsElem
for checking; thus the note there applies here.
type family AllIsElem (xs :: [*]) api :: Constraint where ... #
Check that every element of xs
is an endpoint of api
(using
).IsElem
type family IsIn endpoint api :: Constraint where ... #
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 deduce... ...
type family IsStrictSubAPI sub api :: Constraint where ... #
IsStrictSubAPI sub api = AllIsIn (Endpoints sub) api |
type family AllIsIn (xs :: [*]) api :: Constraint where ... #
Check that every element of xs
is an endpoint of api
(using
).IsIn
ok (Proxy :: Proxy (AllIsIn (Endpoints SampleAPI) SampleAPI)) OK
type family AppendList (xs :: [a]) (ys :: [a]) :: [a] where ... #
Append two type-level lists.
AppendList ([] :: [a]) (ys :: [a]) = ys | |
AppendList (x ': xs :: [a]) (ys :: [a]) = x ': AppendList xs ys |
type family IsSubList (a :: [t]) (b :: [t]) :: Constraint where ... #
type Elem (e :: t) (es :: [t]) = ElemGo e es es #
Check 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... ...
type family ElemGo (e :: t) (es :: [t]) (orig :: t1) :: Constraint where ... #
data Verb (method :: k1) (statusCode :: Nat) (contentTypes :: [*]) a :: forall k1. k1 -> Nat -> [*] -> * -> * #
Verb
is a general type for representing HTTP verbs (a.k.a. methods). For
convenience, type synonyms for each verb with a 200 response code are
provided, but you are free to define your own:
>>>
type Post204 contentTypes a = Verb 'POST 204 contentTypes a
Instances
HasLink (Verb m s ct a :: *) | |
(AllCTRender ctypes a, ReflectMethod method, KnownNat status) => HasServer (Verb method status ctypes a :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Verb method status ctypes a) -> Context context -> Delayed env (Server (Verb method status ctypes a)) -> Router env # hoistServerWithContext :: Proxy (Verb method status ctypes a) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes a) m -> ServerT (Verb method status ctypes a) n # | |
(AllCTRender ctypes a, ReflectMethod method, KnownNat status, GetHeaders (Headers h a)) => HasServer (Verb method status ctypes (Headers h a) :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Verb method status ctypes (Headers h a)) -> Context context -> Delayed env (Server (Verb method status ctypes (Headers h a))) -> Router env # hoistServerWithContext :: Proxy (Verb method status ctypes (Headers h a)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes (Headers h a)) m -> ServerT (Verb method status ctypes (Headers h a)) n # | |
Generic (Verb method statusCode contentTypes a) | |
type MkLink (Verb m s ct a :: *) r | |
Defined in Servant.Links | |
type ServerT (Verb method status ctypes (Headers h a) :: *) m | |
type ServerT (Verb method status ctypes a :: *) m | |
Defined in Servant.Server.Internal | |
type Rep (Verb method statusCode contentTypes a) | |
type PostCreated = Verb POST 201 #
POST
with 201 status code.
type GetAccepted = Verb GET 202 #
GET
with 202 status code.
type PostAccepted = Verb POST 202 #
POST
with 202 status code.
type DeleteAccepted = Verb DELETE 202 #
DELETE
with 202 status code.
type PatchAccepted = Verb PATCH 202 #
PATCH
with 202 status code.
type PutAccepted = Verb PUT 202 #
PUT
with 202 status code.
type GetNonAuthoritative = Verb GET 203 #
GET
with 203 status code.
type PostNonAuthoritative = Verb POST 203 #
POST
with 203 status code.
type DeleteNonAuthoritative = Verb DELETE 203 #
DELETE
with 203 status code.
type PatchNonAuthoritative = Verb PATCH 203 #
PATCH
with 203 status code.
type PutNonAuthoritative = Verb PUT 203 #
PUT
with 203 status code.
type GetNoContent = Verb GET 204 #
GET
with 204 status code.
type PostNoContent = Verb POST 204 #
POST
with 204 status code.
type DeleteNoContent = Verb DELETE 204 #
DELETE
with 204 status code.
type PatchNoContent = Verb PATCH 204 #
PATCH
with 204 status code.
type PutNoContent = Verb PUT 204 #
PUT
with 204 status code.
type GetResetContent = Verb GET 205 #
GET
with 205 status code.
type PostResetContent = Verb POST 205 #
POST
with 205 status code.
type GetPartialContent = Verb GET 206 #
GET
with 206 status code.
class ReflectMethod (a :: k) where #
reflectMethod :: Proxy a -> Method #
Instances
ReflectMethod PATCH | |
Defined in Servant.API.Verbs reflectMethod :: Proxy PATCH -> Method # | |
ReflectMethod OPTIONS | |
Defined in Servant.API.Verbs reflectMethod :: Proxy OPTIONS -> Method # | |
ReflectMethod CONNECT | |
Defined in Servant.API.Verbs reflectMethod :: Proxy CONNECT -> Method # | |
ReflectMethod TRACE | |
Defined in Servant.API.Verbs reflectMethod :: Proxy TRACE -> Method # | |
ReflectMethod DELETE | |
Defined in Servant.API.Verbs reflectMethod :: Proxy DELETE -> Method # | |
ReflectMethod PUT | |
Defined in Servant.API.Verbs reflectMethod :: Proxy PUT -> Method # | |
ReflectMethod HEAD | |
Defined in Servant.API.Verbs reflectMethod :: Proxy HEAD -> Method # | |
ReflectMethod POST | |
Defined in Servant.API.Verbs reflectMethod :: Proxy POST -> Method # | |
ReflectMethod GET | |
Defined in Servant.API.Verbs reflectMethod :: Proxy GET -> Method # |
data (path :: k) :> a :: forall k. k -> * -> * infixr 4 #
The contained API (second argument) can be found under ("/" ++ path)
(path being the first argument).
Example:
>>>
-- GET /hello/world
>>>
-- returning a JSON encoded World value
>>>
type MyApi = "hello" :> "world" :> Get '[JSON] World
Instances
HasLink sub => HasLink (HttpVersion :> sub :: *) | |
Defined in Servant.Links type MkLink (HttpVersion :> sub) a :: * # toLink :: (Link -> a) -> Proxy (HttpVersion :> sub) -> Link -> MkLink (HttpVersion :> sub) a # | |
HasLink sub => HasLink (ReqBody' mods ct a :> sub :: *) | |
HasLink sub => HasLink (RemoteHost :> sub :: *) | |
Defined in Servant.Links type MkLink (RemoteHost :> sub) a :: * # toLink :: (Link -> a) -> Proxy (RemoteHost :> sub) -> Link -> MkLink (RemoteHost :> sub) a # | |
(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub :: *) | |
Defined in Servant.Links type MkLink (QueryParam' mods sym v :> sub) a :: * # toLink :: (Link -> a) -> Proxy (QueryParam' mods sym v :> sub) -> Link -> MkLink (QueryParam' mods sym v :> sub) a # | |
(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub :: *) | |
Defined in Servant.Links type MkLink (QueryParams sym v :> sub) a :: * # toLink :: (Link -> a) -> Proxy (QueryParams sym v :> sub) -> Link -> MkLink (QueryParams sym v :> sub) a # | |
(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub :: *) | |
HasLink sub => HasLink (Header' mods sym a :> sub :: *) | |
HasLink sub => HasLink (IsSecure :> sub :: *) | |
HasLink sub => HasLink (AuthProtect tag :> sub :: *) | |
Defined in Servant.Links type MkLink (AuthProtect tag :> sub) a :: * # toLink :: (Link -> a) -> Proxy (AuthProtect tag :> sub) -> Link -> MkLink (AuthProtect tag :> sub) a # | |
HasLink sub => HasLink (Summary s :> sub :: *) | |
HasLink sub => HasLink (Description s :> sub :: *) | |
Defined in Servant.Links type MkLink (Description s :> sub) a :: * # toLink :: (Link -> a) -> Proxy (Description s :> sub) -> Link -> MkLink (Description s :> sub) a # | |
(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub :: *) | |
(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub :: *) | |
Defined in Servant.Links type MkLink (CaptureAll sym v :> sub) a :: * # toLink :: (Link -> a) -> Proxy (CaptureAll sym v :> sub) -> Link -> MkLink (CaptureAll sym v :> sub) a # | |
HasLink sub => HasLink (BasicAuth realm a :> sub :: *) | |
HasLink sub => HasLink (Vault :> sub :: *) | |
(KnownSymbol sym, HasLink sub) => HasLink (sym :> sub :: *) | |
(TypeError (HasServerArrowKindError arr) :: Constraint) => HasServer (arr :> api :: *) context | This instance catches mistakes when there are non-saturated
type applications on LHS of
|
Defined in Servant.Server.Internal | |
HasServer api context => HasServer (HttpVersion :> api :: *) context | |
Defined in Servant.Server.Internal type ServerT (HttpVersion :> api) m :: * # route :: Proxy (HttpVersion :> api) -> Context context -> Delayed env (Server (HttpVersion :> api)) -> Router env # hoistServerWithContext :: Proxy (HttpVersion :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (HttpVersion :> api) m -> ServerT (HttpVersion :> api) n # | |
(AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods)) => HasServer (ReqBody' mods list a :> api :: *) context | If you use All it asks is for a 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... |
Defined in Servant.Server.Internal route :: Proxy (ReqBody' mods list a :> api) -> Context context -> Delayed env (Server (ReqBody' mods list a :> api)) -> Router env # hoistServerWithContext :: Proxy (ReqBody' mods list a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (ReqBody' mods list a :> api) m -> ServerT (ReqBody' mods list a :> api) n # | |
HasServer api context => HasServer (RemoteHost :> api :: *) context | |
Defined in Servant.Server.Internal type ServerT (RemoteHost :> api) m :: * # route :: Proxy (RemoteHost :> api) -> Context context -> Delayed env (Server (RemoteHost :> api)) -> Router env # hoistServerWithContext :: Proxy (RemoteHost :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (RemoteHost :> api) m -> ServerT (RemoteHost :> api) n # | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => HasServer (QueryParam' mods sym a :> api :: *) context | If you use 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 You can control how it'll be converted from 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... |
Defined in Servant.Server.Internal type ServerT (QueryParam' mods sym a :> api) m :: * # route :: Proxy (QueryParam' mods sym a :> api) -> Context context -> Delayed env (Server (QueryParam' mods sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (QueryParam' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParam' mods sym a :> api) m -> ServerT (QueryParam' mods sym a :> api) n # | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context) => HasServer (QueryParams sym a :> api :: *) context | If you use This lets servant worry about looking up 0 or more values in the query string
associated to You can control how the individual values are converted from 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... |
Defined in Servant.Server.Internal type ServerT (QueryParams sym a :> api) m :: * # route :: Proxy (QueryParams sym a :> api) -> Context context -> Delayed env (Server (QueryParams sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (QueryParams sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParams sym a :> api) m -> ServerT (QueryParams sym a :> api) n # | |
(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api :: *) context | If you use 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... |
Defined in Servant.Server.Internal | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => HasServer (Header' mods sym a :> api :: *) context | If you use All it asks is for a 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 |
Defined in Servant.Server.Internal route :: Proxy (Header' mods sym a :> api) -> Context context -> Delayed env (Server (Header' mods sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (Header' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Header' mods sym a :> api) m -> ServerT (Header' mods sym a :> api) n # | |
HasServer api context => HasServer (IsSecure :> api :: *) context | |
Defined in Servant.Server.Internal | |
HasServer api ctx => HasServer (Summary desc :> api :: *) ctx | Ignore |
Defined in Servant.Server.Internal | |
HasServer api ctx => HasServer (Description desc :> api :: *) ctx | Ignore |
Defined in Servant.Server.Internal type ServerT (Description desc :> api) m :: * # route :: Proxy (Description desc :> api) -> Context ctx -> Delayed env (Server (Description desc :> api)) -> Router env # hoistServerWithContext :: Proxy (Description desc :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (Description desc :> api) m -> ServerT (Description desc :> api) n # | |
(KnownSymbol capture, FromHttpApiData a, HasServer api context) => HasServer (Capture' mods capture a :> api :: *) context | If you use You can control how it'll be converted from Example: type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book server :: Server MyApi server = getBook where getBook :: Text -> Handler Book getBook isbn = ... |
Defined in Servant.Server.Internal route :: Proxy (Capture' mods capture a :> api) -> Context context -> Delayed env (Server (Capture' mods capture a :> api)) -> Router env # hoistServerWithContext :: Proxy (Capture' mods capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Capture' mods capture a :> api) m -> ServerT (Capture' mods capture a :> api) n # | |
(KnownSymbol capture, FromHttpApiData a, HasServer api context) => HasServer (CaptureAll capture a :> api :: *) context | If you use You can control how they'll be converted from Example: type MyApi = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile server :: Server MyApi server = getSourceFile where getSourceFile :: [Text] -> Handler Book getSourceFile pathSegments = ... |
Defined in Servant.Server.Internal type ServerT (CaptureAll capture a :> api) m :: * # route :: Proxy (CaptureAll capture a :> api) -> Context context -> Delayed env (Server (CaptureAll capture a :> api)) -> Router env # hoistServerWithContext :: Proxy (CaptureAll capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (CaptureAll capture a :> api) m -> ServerT (CaptureAll capture a :> api) n # | |
(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api :: *) context | Basic Authentication |
Defined in Servant.Server.Internal route :: Proxy (BasicAuth realm usr :> api) -> Context context -> Delayed env (Server (BasicAuth realm usr :> api)) -> Router env # hoistServerWithContext :: Proxy (BasicAuth realm usr :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (BasicAuth realm usr :> api) m -> ServerT (BasicAuth realm usr :> api) n # | |
HasServer api context => HasServer (Vault :> api :: *) context | |
Defined in Servant.Server.Internal | |
(KnownSymbol path, HasServer api context) => HasServer (path :> api :: *) context | Make sure the incoming request starts with |
Defined in Servant.Server.Internal | |
type MkLink (HttpVersion :> sub :: *) a | |
Defined in Servant.Links | |
type MkLink (ReqBody' mods ct a :> sub :: *) r | |
type MkLink (RemoteHost :> sub :: *) a | |
Defined in Servant.Links | |
type MkLink (QueryParam' mods sym v :> sub :: *) a | |
Defined in Servant.Links type MkLink (QueryParam' mods sym v :> sub :: *) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub a | |
type MkLink (QueryParams sym v :> sub :: *) a | |
Defined in Servant.Links | |
type MkLink (QueryFlag sym :> sub :: *) a | |
type MkLink (Header' mods sym a :> sub :: *) r | |
type MkLink (IsSecure :> sub :: *) a | |
type MkLink (AuthProtect tag :> sub :: *) a | |
Defined in Servant.Links | |
type MkLink (Summary s :> sub :: *) a | |
type MkLink (Description s :> sub :: *) a | |
Defined in Servant.Links | |
type MkLink (Capture' mods sym v :> sub :: *) a | |
type MkLink (CaptureAll sym v :> sub :: *) a | |
Defined in Servant.Links | |
type MkLink (BasicAuth realm a :> sub :: *) r | |
type MkLink (Vault :> sub :: *) a | |
type MkLink (sym :> sub :: *) a | |
Defined in Servant.Links | |
type ServerT (arr :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (HttpVersion :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (ReqBody' mods list a :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (RemoteHost :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (QueryParam' mods sym a :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (QueryParams sym a :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (QueryFlag sym :> api :: *) m | |
type ServerT (Header' mods sym a :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (IsSecure :> api :: *) m | |
type ServerT (Summary desc :> api :: *) m | |
type ServerT (Description desc :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (Capture' mods capture a :> api :: *) m | |
type ServerT (CaptureAll capture a :> api :: *) m | |
Defined in Servant.Server.Internal | |
type ServerT (BasicAuth realm usr :> api :: *) m | |
type ServerT (Vault :> api :: *) m | |
type ServerT (path :> api :: *) m | |
Defined in Servant.Server.Internal |
data Stream (method :: k1) (status :: Nat) framing contentType a :: forall k1. k1 -> Nat -> * -> * -> * -> * #
A Stream endpoint for a given method emits a stream of encoded values at a given Content-Type, delimited by a framing strategy. Stream endpoints always return response code 200 on success. Type synonyms are provided for standard methods.
Instances
HasLink (Stream m status fr ct a :: *) | |
(MimeRender ctype a, ReflectMethod method, KnownNat status, FramingRender framing ctype, ToStreamGenerator b a) => HasServer (Stream method status framing ctype b :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Stream method status framing ctype b) -> Context context -> Delayed env (Server (Stream method status framing ctype b)) -> Router env # hoistServerWithContext :: Proxy (Stream method status framing ctype b) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype b) m -> ServerT (Stream method status framing ctype b) n # | |
(MimeRender ctype a, ReflectMethod method, KnownNat status, FramingRender framing ctype, ToStreamGenerator b a, GetHeaders (Headers h b)) => HasServer (Stream method status framing ctype (Headers h b) :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Stream method status framing ctype (Headers h b)) -> Context context -> Delayed env (Server (Stream method status framing ctype (Headers h b))) -> Router env # hoistServerWithContext :: Proxy (Stream method status framing ctype (Headers h b)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype (Headers h b)) m -> ServerT (Stream method status framing ctype (Headers h b)) n # | |
Generic (Stream method status framing contentType a) | |
Defined in Servant.API.Stream | |
type MkLink (Stream m status fr ct a :: *) r | |
Defined in Servant.Links | |
type ServerT (Stream method status framing ctype (Headers h b) :: *) m | |
type ServerT (Stream method status framing ctype b :: *) m | |
Defined in Servant.Server.Internal | |
type Rep (Stream method status framing contentType a) | |
type StreamPost = Stream POST 200 #
newtype StreamGenerator a #
Stream endpoints may be implemented as producing a StreamGenerator
-- a function that itself takes two emit functions -- the first to be used on the first value the stream emits, and the second to be used on all subsequent values (to allow interspersed framing strategies such as comma separation).
StreamGenerator | |
|
Instances
ToStreamGenerator (StreamGenerator a) a | |
Defined in Servant.API.Stream toStreamGenerator :: StreamGenerator a -> StreamGenerator a # |
class ToStreamGenerator a b | a -> b where #
ToStreamGenerator 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.
toStreamGenerator :: a -> StreamGenerator b #
Instances
ToStreamGenerator (StreamGenerator a) a | |
Defined in Servant.API.Stream toStreamGenerator :: StreamGenerator a -> StreamGenerator a # |
newtype ResultStream a #
Clients reading from streaming endpoints can be implemented as producing a ResultStream
that captures the setup, takedown, and incremental logic for a read, being an IO continuation that takes a producer of Just either values or errors that terminates with a Nothing.
Instances
BuildFromStream a (ResultStream a) | |
Defined in Servant.API.Stream buildFromStream :: ResultStream a -> ResultStream a # |
class BuildFromStream a b where #
BuildFromStream 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.
buildFromStream :: ResultStream a -> b #
Instances
BuildFromStream a (ResultStream a) | |
Defined in Servant.API.Stream buildFromStream :: ResultStream a -> ResultStream a # |
class FramingRender (strategy :: k) (a :: k1) where #
The FramingRender class provides the logic for emitting a framing strategy. The strategy emits a header, followed by boundary-delimited data, and finally a termination character. For many strategies, some of these will just be empty bytestrings.
header :: Proxy strategy -> Proxy a -> ByteString #
boundary :: Proxy strategy -> Proxy a -> BoundaryStrategy #
trailer :: Proxy strategy -> Proxy a -> ByteString #
Instances
FramingRender NoFraming (a :: k) | |
Defined in Servant.API.Stream | |
FramingRender NewlineFraming (a :: k) | |
Defined in Servant.API.Stream header :: Proxy NewlineFraming -> Proxy a -> ByteString # boundary :: Proxy NewlineFraming -> Proxy a -> BoundaryStrategy # trailer :: Proxy NewlineFraming -> Proxy a -> ByteString # | |
FramingRender NetstringFraming (a :: k) | |
Defined in Servant.API.Stream header :: Proxy NetstringFraming -> Proxy a -> ByteString # boundary :: Proxy NetstringFraming -> Proxy a -> BoundaryStrategy # trailer :: Proxy NetstringFraming -> Proxy a -> ByteString # |
data BoundaryStrategy #
The bracketing strategy generates things to precede and follow the content, as with netstrings. The intersperse strategy inserts seperators between things, as with newline framing. Finally, the general strategy performs an arbitrary rewrite on the content, to allow escaping rules and such.
data ByteStringParser a #
A type of parser that can never fail, and has different parsing strategies (incremental, or EOF) depending if more input can be sent. The incremental parser should return Nothing
if it would like to be sent a longer ByteString. If it returns a value, it also returns the remainder following that value.
ByteStringParser | |
|
class FramingUnrender (strategy :: k) (a :: k1) where #
The FramingUnrender class provides the logic for parsing a framing strategy. The outer ByteStringParser
strips the header from a stream of bytes, and yields a parser that can handle the remainder, stepwise. Each frame may be a ByteString, or a String indicating the error state for that frame. Such states are per-frame, so that protocols that can resume after errors are able to do so. Eventually this returns an empty ByteString to indicate termination.
unrenderFrames :: Proxy strategy -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) #
Instances
FramingUnrender NoFraming (a :: k) | |
Defined in Servant.API.Stream unrenderFrames :: Proxy NoFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
FramingUnrender NewlineFraming (a :: k) | |
Defined in Servant.API.Stream unrenderFrames :: Proxy NewlineFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
FramingUnrender NetstringFraming (a :: k) | |
Defined in Servant.API.Stream unrenderFrames :: Proxy NetstringFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # |
A framing strategy that does not do any framing at all, it just passes the input data This will be used most of the time with binary data, such as files
Instances
FramingRender NoFraming (a :: k) | |
Defined in Servant.API.Stream | |
FramingUnrender NoFraming (a :: k) | |
Defined in Servant.API.Stream unrenderFrames :: Proxy NoFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # |
data NewlineFraming #
A simple framing strategy that has no header or termination, and inserts a newline character between each frame. This assumes that it is used with a Content-Type that encodes without newlines (e.g. JSON).
Instances
FramingRender NewlineFraming (a :: k) | |
Defined in Servant.API.Stream header :: Proxy NewlineFraming -> Proxy a -> ByteString # boundary :: Proxy NewlineFraming -> Proxy a -> BoundaryStrategy # trailer :: Proxy NewlineFraming -> Proxy a -> ByteString # | |
FramingUnrender NewlineFraming (a :: k) | |
Defined in Servant.API.Stream unrenderFrames :: Proxy NewlineFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # |
data NetstringFraming #
The netstring framing strategy as defined by djb: http://cr.yp.to/proto/netstrings.txt
Instances
FramingRender NetstringFraming (a :: k) | |
Defined in Servant.API.Stream header :: Proxy NetstringFraming -> Proxy a -> ByteString # boundary :: Proxy NetstringFraming -> Proxy a -> BoundaryStrategy # trailer :: Proxy NetstringFraming -> Proxy a -> ByteString # | |
FramingUnrender NetstringFraming (a :: k) | |
Defined in Servant.API.Stream unrenderFrames :: Proxy NetstringFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # |
noHeader :: AddHeader h v orig new => orig -> new #
Deliberately do not add a header to a value.
>>>
let example1 = noHeader "hi" :: Headers '[Header "someheader" Int] String
>>>
getHeaders example1
[]
addHeader :: AddHeader h v orig new => v -> orig -> new #
addHeader
adds a header to a response. Note that it changes the type of
the value in the following ways:
- A simple value is wrapped in "Headers '[hdr]":
>>>
let example1 = addHeader 5 "hi" :: Headers '[Header "someheader" Int] String;
>>>
getHeaders example1
[("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] String
>>>
getHeaders 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.
Response Header objects. You should never need to construct one directly.
Instead, use addOptionalHeader
.
Headers | |
|
Instances
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) | |
Defined in Servant.API.ResponseHeaders addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a | |
Functor (Headers ls) | |
(AllCTRender ctypes a, ReflectMethod method, KnownNat status, GetHeaders (Headers h a)) => HasServer (Verb method status ctypes (Headers h a) :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Verb method status ctypes (Headers h a)) -> Context context -> Delayed env (Server (Verb method status ctypes (Headers h a))) -> Router env # hoistServerWithContext :: Proxy (Verb method status ctypes (Headers h a)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes (Headers h a)) m -> ServerT (Verb method status ctypes (Headers h a)) n # | |
(MimeRender ctype a, ReflectMethod method, KnownNat status, FramingRender framing ctype, ToStreamGenerator b a, GetHeaders (Headers h b)) => HasServer (Stream method status framing ctype (Headers h b) :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Stream method status framing ctype (Headers h b)) -> Context context -> Delayed env (Server (Stream method status framing ctype (Headers h b))) -> Router env # hoistServerWithContext :: Proxy (Stream method status framing ctype (Headers h b)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype (Headers h b)) m -> ServerT (Stream method status framing ctype (Headers h b)) n # | |
GetHeaders' hs => GetHeaders (Headers hs a) | |
Defined in Servant.API.ResponseHeaders getHeaders :: Headers hs a -> [Header] # | |
type ServerT (Verb method status ctypes (Headers h a) :: *) m | |
type ServerT (Stream method status framing ctype (Headers h b) :: *) m | |
data ResponseHeader (sym :: Symbol) a #
Instances
Functor (ResponseHeader sym) | |
Defined in Servant.API.ResponseHeaders fmap :: (a -> b) -> ResponseHeader sym a -> ResponseHeader sym b # (<$) :: a -> ResponseHeader sym b -> ResponseHeader sym a # | |
Eq a => Eq (ResponseHeader sym a) | |
Defined in Servant.API.ResponseHeaders (==) :: ResponseHeader sym a -> ResponseHeader sym a -> Bool # (/=) :: ResponseHeader sym a -> ResponseHeader sym a -> Bool # | |
Show a => Show (ResponseHeader sym a) | |
Defined in Servant.API.ResponseHeaders showsPrec :: Int -> ResponseHeader sym a -> ShowS # show :: ResponseHeader sym a -> String # showList :: [ResponseHeader sym a] -> ShowS # |
Instances
GetHeadersFromHList hs => GetHeaders (HList hs) | |
Defined in Servant.API.ResponseHeaders getHeaders :: HList hs -> [Header] # |
class BuildHeadersTo (hs :: [*]) where #
buildHeadersTo :: [Header] -> HList hs #
Note: if there are multiple occurences of a header in the argument, the values are interspersed with commas before deserialization (see RFC2616 Sec 4.2)
Instances
BuildHeadersTo ([] :: [*]) | |
Defined in Servant.API.ResponseHeaders buildHeadersTo :: [Header] -> HList [] # | |
(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) | |
Defined in Servant.API.ResponseHeaders buildHeadersTo :: [Header0] -> HList (Header h v ': xs) # |
class GetHeaders ls where #
getHeaders :: ls -> [Header] #
Instances
GetHeadersFromHList hs => GetHeaders (HList hs) | |
Defined in Servant.API.ResponseHeaders getHeaders :: HList hs -> [Header] # | |
GetHeaders' hs => GetHeaders (Headers hs a) | |
Defined in Servant.API.ResponseHeaders getHeaders :: Headers hs a -> [Header] # |
class AddHeader (h :: Symbol) v orig new | h v orig -> new, new -> h, new -> v, new -> orig #
addOptionalHeader
Instances
(KnownSymbol h, ToHttpApiData v, new ~ Headers (Header h v ': ([] :: [*])) a) => AddHeader h v a new | |
Defined in Servant.API.ResponseHeaders addOptionalHeader :: ResponseHeader h v -> a -> new | |
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) | |
Defined in Servant.API.ResponseHeaders addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a |
type ReqBody = ReqBody' (Required ': (Strict ': ([] :: [*]))) #
Extract the request body as a value of type a
.
Example:
>>>
-- POST /books
>>>
type MyApi = "books" :> ReqBody '[JSON] Book :> Post '[JSON] Book
data ReqBody' (mods :: [*]) (contentTypes :: [*]) a #
Instances
HasLink sub => HasLink (ReqBody' mods ct a :> sub :: *) | |
(AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods)) => HasServer (ReqBody' mods list a :> api :: *) context | If you use All it asks is for a 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... |
Defined in Servant.Server.Internal route :: Proxy (ReqBody' mods list a :> api) -> Context context -> Delayed env (Server (ReqBody' mods list a :> api)) -> Router env # hoistServerWithContext :: Proxy (ReqBody' mods list a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (ReqBody' mods list a :> api) m -> ServerT (ReqBody' mods list a :> api) n # | |
type MkLink (ReqBody' mods ct a :> sub :: *) r | |
type ServerT (ReqBody' mods list a :> api :: *) m | |
Defined in Servant.Server.Internal |
data RemoteHost #
Provides access to the host or IP address from which the HTTP request was sent.
Instances
HasLink sub => HasLink (RemoteHost :> sub :: *) | |
Defined in Servant.Links type MkLink (RemoteHost :> sub) a :: * # toLink :: (Link -> a) -> Proxy (RemoteHost :> sub) -> Link -> MkLink (RemoteHost :> sub) a # | |
HasServer api context => HasServer (RemoteHost :> api :: *) context | |
Defined in Servant.Server.Internal type ServerT (RemoteHost :> api) m :: * # route :: Proxy (RemoteHost :> api) -> Context context -> Delayed env (Server (RemoteHost :> api)) -> Router env # hoistServerWithContext :: Proxy (RemoteHost :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (RemoteHost :> api) m -> ServerT (RemoteHost :> api) n # | |
type MkLink (RemoteHost :> sub :: *) a | |
Defined in Servant.Links | |
type ServerT (RemoteHost :> api :: *) m | |
Defined in Servant.Server.Internal |
Endpoint for plugging in your own Wai Application
s.
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 Application
s,
this can also be used with serveDirectory to serve
static files stored in a particular directory on your filesystem
Instances
HasLink Raw | |
HasServer Raw context | Just pass the request to the underlying application and serve its response. Example: type MyApi = "images" :> Raw server :: Server MyApi server = serveDirectory "/var/www/images" |
type MkLink Raw a | |
Defined in Servant.Links | |
type ServerT Raw m | |
Defined in Servant.Server.Internal |
type QueryParam = QueryParam' (Optional ': (Strict ': ([] :: [*]))) #
Lookup the value associated to the sym
query string parameter
and try to extract it as a value of type a
.
Example:
>>>
-- /books?author=<author name>
>>>
type MyApi = "books" :> QueryParam "author" Text :> Get '[JSON] [Book]
data QueryParam' (mods :: [*]) (sym :: Symbol) a #
QueryParam
which can be Required
, Lenient
, or modified otherwise.
Instances
(KnownSymbol sym, ToHttpApiData v, HasLink sub, SBoolI (FoldRequired mods)) => HasLink (QueryParam' mods sym v :> sub :: *) | |
Defined in Servant.Links type MkLink (QueryParam' mods sym v :> sub) a :: * # toLink :: (Link -> a) -> Proxy (QueryParam' mods sym v :> sub) -> Link -> MkLink (QueryParam' mods sym v :> sub) a # | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => HasServer (QueryParam' mods sym a :> api :: *) context | If you use 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 You can control how it'll be converted from 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... |
Defined in Servant.Server.Internal type ServerT (QueryParam' mods sym a :> api) m :: * # route :: Proxy (QueryParam' mods sym a :> api) -> Context context -> Delayed env (Server (QueryParam' mods sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (QueryParam' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParam' mods sym a :> api) m -> ServerT (QueryParam' mods sym a :> api) n # | |
type MkLink (QueryParam' mods sym v :> sub :: *) a | |
Defined in Servant.Links type MkLink (QueryParam' mods sym v :> sub :: *) a = If (FoldRequired mods) v (Maybe v) -> MkLink sub a | |
type ServerT (QueryParam' mods sym a :> api :: *) m | |
Defined in Servant.Server.Internal |
data QueryParams (sym :: Symbol) a #
Lookup the values associated to the sym
query string parameter
and try to extract it as a value of type [a]
. This is typically
meant to support query string parameters of the form
param[]=val1¶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]
Instances
(KnownSymbol sym, ToHttpApiData v, HasLink sub) => HasLink (QueryParams sym v :> sub :: *) | |
Defined in Servant.Links type MkLink (QueryParams sym v :> sub) a :: * # toLink :: (Link -> a) -> Proxy (QueryParams sym v :> sub) -> Link -> MkLink (QueryParams sym v :> sub) a # | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context) => HasServer (QueryParams sym a :> api :: *) context | If you use This lets servant worry about looking up 0 or more values in the query string
associated to You can control how the individual values are converted from 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... |
Defined in Servant.Server.Internal type ServerT (QueryParams sym a :> api) m :: * # route :: Proxy (QueryParams sym a :> api) -> Context context -> Delayed env (Server (QueryParams sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (QueryParams sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParams sym a :> api) m -> ServerT (QueryParams sym a :> api) n # | |
type MkLink (QueryParams sym v :> sub :: *) a | |
Defined in Servant.Links | |
type ServerT (QueryParams sym a :> api :: *) m | |
Defined in Servant.Server.Internal |
data QueryFlag (sym :: Symbol) #
Lookup a potentially value-less query string parameter
with boolean semantics. If the param sym
is there without any value,
or if it's there with value "true" or "1", it's interpreted as True
.
Otherwise, it's interpreted as False
.
Example:
>>>
-- /books?published
>>>
type MyApi = "books" :> QueryFlag "published" :> Get '[JSON] [Book]
Instances
(KnownSymbol sym, HasLink sub) => HasLink (QueryFlag sym :> sub :: *) | |
(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api :: *) context | If you use 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... |
Defined in Servant.Server.Internal | |
type MkLink (QueryFlag sym :> sub :: *) a | |
type ServerT (QueryFlag sym :> api :: *) m | |
type Header = (Header' (Optional ': (Strict ': ([] :: [*]))) :: Symbol -> k -> *) #
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-referer
>>>
type MyApi = "view-my-referer" :> Header "from" Referer :> Get '[JSON] Referer
data Header' (mods :: [*]) (sym :: Symbol) (a :: k) :: forall k. [*] -> Symbol -> k -> * #
Instances
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) | |
Defined in Servant.API.ResponseHeaders addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a | |
HasLink sub => HasLink (Header' mods sym a :> sub :: *) | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => HasServer (Header' mods sym a :> api :: *) context | If you use All it asks is for a 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 |
Defined in Servant.Server.Internal route :: Proxy (Header' mods sym a :> api) -> Context context -> Delayed env (Server (Header' mods sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (Header' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Header' mods sym a :> api) m -> ServerT (Header' mods sym a :> api) n # | |
(KnownSymbol h, ToHttpApiData x, GetHeadersFromHList xs) => GetHeadersFromHList (Header h x ': xs) | |
Defined in Servant.API.ResponseHeaders getHeadersFromHList :: HList (Header h x ': xs) -> [Header0] | |
(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) | |
Defined in Servant.API.ResponseHeaders getHeaders' :: Headers (Header h v ': rest) a -> [Header0] | |
(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) | |
Defined in Servant.API.ResponseHeaders buildHeadersTo :: [Header0] -> HList (Header h v ': xs) # | |
type MkLink (Header' mods sym a :> sub :: *) r | |
type ServerT (Header' mods sym a :> api :: *) m | |
Defined in Servant.Server.Internal |
Optional argument. Wrapped in Maybe
.
Instances
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) | |
Defined in Servant.API.ResponseHeaders addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a | |
(KnownSymbol h, ToHttpApiData x, GetHeadersFromHList xs) => GetHeadersFromHList (Header h x ': xs) | |
Defined in Servant.API.ResponseHeaders getHeadersFromHList :: HList (Header h x ': xs) -> [Header0] | |
(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) | |
Defined in Servant.API.ResponseHeaders getHeaders' :: Headers (Header h v ': rest) a -> [Header0] | |
(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) | |
Defined in Servant.API.ResponseHeaders buildHeadersTo :: [Header0] -> HList (Header h v ': xs) # |
Strictly parsed argument. Not wrapped.
Instances
(KnownSymbol h, ToHttpApiData v) => AddHeader h v (Headers (fst ': rest) a) (Headers (Header h v ': (fst ': rest)) a) | |
Defined in Servant.API.ResponseHeaders addOptionalHeader :: ResponseHeader h v -> Headers (fst ': rest) a -> Headers (Header h v ': (fst ': rest)) a | |
(KnownSymbol h, ToHttpApiData x, GetHeadersFromHList xs) => GetHeadersFromHList (Header h x ': xs) | |
Defined in Servant.API.ResponseHeaders getHeadersFromHList :: HList (Header h x ': xs) -> [Header0] | |
(KnownSymbol h, GetHeadersFromHList rest, ToHttpApiData v) => GetHeaders' (Header h v ': rest) | |
Defined in Servant.API.ResponseHeaders getHeaders' :: Headers (Header h v ': rest) a -> [Header0] | |
(FromHttpApiData v, BuildHeadersTo xs, KnownSymbol h) => BuildHeadersTo (Header h v ': xs) | |
Defined in Servant.API.ResponseHeaders buildHeadersTo :: [Header0] -> HList (Header h v ': xs) # |
Was this request made over an SSL connection?
Note that this value will not tell you if the client originally
made this request over SSL, but rather whether the current
connection is SSL. The distinction lies with reverse proxies.
In many cases, the client will connect to a load balancer over SSL,
but connect to the WAI handler without SSL. In such a case,
the handlers would get NotSecure
, but from a user perspective,
there is a secure connection.
Secure | the connection to the server is secure (HTTPS) |
NotSecure | the connection to the server is not secure (HTTP) |
Instances
Eq IsSecure | |
Ord IsSecure | |
Defined in Servant.API.IsSecure | |
Read IsSecure | |
Show IsSecure | |
Generic IsSecure | |
HasLink sub => HasLink (IsSecure :> sub :: *) | |
HasServer api context => HasServer (IsSecure :> api :: *) context | |
Defined in Servant.Server.Internal | |
type Rep IsSecure | |
type MkLink (IsSecure :> sub :: *) a | |
type ServerT (IsSecure :> api :: *) m | |
data AuthProtect (tag :: k) :: forall k. k -> * #
A generalized Authentication combinator. Use this if you have a non-standard authentication technique.
NOTE: THIS API IS EXPERIMENTAL AND SUBJECT TO CHANGE.
Instances
HasLink sub => HasLink (AuthProtect tag :> sub :: *) | |
Defined in Servant.Links type MkLink (AuthProtect tag :> sub) a :: * # toLink :: (Link -> a) -> Proxy (AuthProtect tag :> sub) -> Link -> MkLink (AuthProtect tag :> sub) a # | |
type MkLink (AuthProtect tag :> sub :: *) a | |
Defined in Servant.Links |
An empty API: one which serves nothing. Morally speaking, this should be
the unit of :<|>
. Implementors of interpretations of API types should
treat EmptyAPI
as close to the unit as possible.
Instances
Bounded EmptyAPI | |
Enum EmptyAPI | |
Eq EmptyAPI | |
Show EmptyAPI | |
HasLink EmptyAPI | |
HasServer EmptyAPI context | The server for an type MyApi = "nothing" :> EmptyApi server :: Server MyApi server = emptyAPIServer |
type MkLink EmptyAPI a | |
Defined in Servant.Links | |
type ServerT EmptyAPI m | |
Defined in Servant.Server.Internal |
data Summary (sym :: Symbol) #
Add a short summary for (part of) API.
Example:
>>>
type MyApi = Summary "Get book by ISBN." :> "books" :> Capture "isbn" Text :> Get '[JSON] Book
data Description (sym :: Symbol) #
Add 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 support is not perfect \ \but it's still very readable." :> Get '[JSON] Book :}
Instances
HasLink sub => HasLink (Description s :> sub :: *) | |
Defined in Servant.Links type MkLink (Description s :> sub) a :: * # toLink :: (Link -> a) -> Proxy (Description s :> sub) -> Link -> MkLink (Description s :> sub) a # | |
HasServer api ctx => HasServer (Description desc :> api :: *) ctx | Ignore |
Defined in Servant.Server.Internal type ServerT (Description desc :> api) m :: * # route :: Proxy (Description desc :> api) -> Context ctx -> Delayed env (Server (Description desc :> api)) -> Router env # hoistServerWithContext :: Proxy (Description desc :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (Description desc :> api) m -> ServerT (Description desc :> api) n # | |
type MkLink (Description s :> sub :: *) a | |
Defined in Servant.Links | |
type ServerT (Description desc :> api :: *) m | |
Defined in Servant.Server.Internal |
Instances
Accept JSON | application/json |
Defined in Servant.API.ContentTypes | |
ToJSON a => MimeRender JSON a | |
Defined in Servant.API.ContentTypes mimeRender :: Proxy JSON -> a -> ByteString # | |
FromJSON a => MimeUnrender JSON a |
|
Defined in Servant.API.ContentTypes mimeUnrender :: Proxy JSON -> ByteString -> Either String a # mimeUnrenderWithType :: Proxy JSON -> MediaType -> ByteString -> Either String a # |
Instances
data FormUrlEncoded #
Instances
Accept FormUrlEncoded | application/x-www-form-urlencoded |
Defined in Servant.API.ContentTypes | |
ToForm a => MimeRender FormUrlEncoded a |
|
Defined in Servant.API.ContentTypes mimeRender :: Proxy FormUrlEncoded -> a -> ByteString # | |
FromForm a => MimeUnrender FormUrlEncoded a |
|
Defined in Servant.API.ContentTypes mimeUnrender :: Proxy FormUrlEncoded -> ByteString -> Either String a # mimeUnrenderWithType :: Proxy FormUrlEncoded -> MediaType -> ByteString -> Either String a # |
data OctetStream #
Instances
Accept OctetStream | application/octet-stream |
Defined in Servant.API.ContentTypes contentType :: Proxy OctetStream -> MediaType # | |
MimeRender OctetStream ByteString | |
Defined in Servant.API.ContentTypes mimeRender :: Proxy OctetStream -> ByteString -> ByteString0 # | |
MimeRender OctetStream ByteString | id |
Defined in Servant.API.ContentTypes mimeRender :: Proxy OctetStream -> ByteString -> ByteString # | |
MimeUnrender OctetStream ByteString | Right . toStrict |
Defined in Servant.API.ContentTypes mimeUnrender :: Proxy OctetStream -> ByteString0 -> Either String ByteString # mimeUnrenderWithType :: Proxy OctetStream -> MediaType -> ByteString0 -> Either String ByteString # | |
MimeUnrender OctetStream ByteString | Right . id |
Defined in Servant.API.ContentTypes mimeUnrender :: Proxy OctetStream -> ByteString -> Either String ByteString # mimeUnrenderWithType :: Proxy OctetStream -> MediaType -> ByteString -> Either String ByteString # |
class Accept (ctype :: k) where #
Instances of Accept
represent mimetypes. They are used for matching
against the Accept
HTTP header of the request, and for setting the
Content-Type
header of the response
Example:
>>>
import Network.HTTP.Media ((//), (/:))
>>>
data HTML
>>>
:{
instance Accept HTML where contentType _ = "text" // "html" /: ("charset", "utf-8") :}
contentType :: Proxy ctype -> MediaType #
contentTypes :: Proxy ctype -> NonEmpty MediaType #
Instances
Accept JSON | application/json |
Defined in Servant.API.ContentTypes | |
Accept PlainText | text/plain;charset=utf-8 |
Defined in Servant.API.ContentTypes | |
Accept FormUrlEncoded | application/x-www-form-urlencoded |
Defined in Servant.API.ContentTypes | |
Accept OctetStream | application/octet-stream |
Defined in Servant.API.ContentTypes contentType :: Proxy OctetStream -> MediaType # |
class Accept ctype => MimeRender (ctype :: k) a where #
Instantiate this class to register a way of serializing a type based
on the Accept
header.
Example:
data MyContentType instance Accept MyContentType where contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8") instance Show a => MimeRender MyContentType a where mimeRender _ val = pack ("This is MINE! " ++ show val) type MyAPI = "path" :> Get '[MyContentType] Int
mimeRender :: Proxy ctype -> a -> ByteString #
Instances
class Accept ctype => MimeUnrender (ctype :: k) a where #
Instantiate this class to register a way of deserializing a type based
on the request's Content-Type
header.
>>>
import Network.HTTP.Media hiding (Accept)
>>>
import qualified Data.ByteString.Lazy.Char8 as BSC
>>>
data MyContentType = MyContentType String
>>>
:{
instance Accept MyContentType where contentType _ = "example" // "prs.me.mine" /: ("charset", "utf-8") :}
>>>
:{
instance Read a => MimeUnrender MyContentType a where mimeUnrender _ bs = case BSC.take 12 bs of "MyContentType" -> return . read . BSC.unpack $ BSC.drop 12 bs _ -> Left "didn't start with the magic incantation" :}
>>>
type MyAPI = "path" :> ReqBody '[MyContentType] Int :> Get '[JSON] Int
mimeUnrender :: Proxy ctype -> ByteString -> Either String a #
mimeUnrenderWithType :: Proxy ctype -> MediaType -> ByteString -> Either String a #
Instances
A type for responses without content-body.
Instances
Eq NoContent | |
Read NoContent | |
Show NoContent | |
Generic NoContent | |
Accept ctyp => AllMimeRender (ctyp ': ([] :: [*])) NoContent | |
Defined in Servant.API.ContentTypes allMimeRender :: Proxy (ctyp ': []) -> NoContent -> [(MediaType, ByteString)] # | |
AllMime (ctyp ': (ctyp' ': ctyps)) => AllMimeRender (ctyp ': (ctyp' ': ctyps)) NoContent | |
Defined in Servant.API.ContentTypes allMimeRender :: Proxy (ctyp ': (ctyp' ': ctyps)) -> NoContent -> [(MediaType, ByteString)] # | |
type Rep NoContent | |
type Capture = Capture' ([] :: [*]) #
Capture a value from the request path under a certain type a
.
Example:
>>>
-- GET /books/:isbn
>>>
type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book
data Capture' (mods :: [*]) (sym :: Symbol) a #
Capture
which can be modified. For example with Description
.
Instances
(ToHttpApiData v, HasLink sub) => HasLink (Capture' mods sym v :> sub :: *) | |
(KnownSymbol capture, FromHttpApiData a, HasServer api context) => HasServer (Capture' mods capture a :> api :: *) context | If you use You can control how it'll be converted from Example: type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book server :: Server MyApi server = getBook where getBook :: Text -> Handler Book getBook isbn = ... |
Defined in Servant.Server.Internal route :: Proxy (Capture' mods capture a :> api) -> Context context -> Delayed env (Server (Capture' mods capture a :> api)) -> Router env # hoistServerWithContext :: Proxy (Capture' mods capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Capture' mods capture a :> api) m -> ServerT (Capture' mods capture a :> api) n # | |
type MkLink (Capture' mods sym v :> sub :: *) a | |
type ServerT (Capture' mods capture a :> api :: *) m | |
data CaptureAll (sym :: Symbol) a #
Capture all remaining values from the request path under a certain type
a
.
Example:
>>>
-- GET /src/*
>>>
type MyAPI = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile
Instances
(ToHttpApiData v, HasLink sub) => HasLink (CaptureAll sym v :> sub :: *) | |
Defined in Servant.Links type MkLink (CaptureAll sym v :> sub) a :: * # toLink :: (Link -> a) -> Proxy (CaptureAll sym v :> sub) -> Link -> MkLink (CaptureAll sym v :> sub) a # | |
(KnownSymbol capture, FromHttpApiData a, HasServer api context) => HasServer (CaptureAll capture a :> api :: *) context | If you use You can control how they'll be converted from Example: type MyApi = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile server :: Server MyApi server = getSourceFile where getSourceFile :: [Text] -> Handler Book getSourceFile pathSegments = ... |
Defined in Servant.Server.Internal type ServerT (CaptureAll capture a :> api) m :: * # route :: Proxy (CaptureAll capture a :> api) -> Context context -> Delayed env (Server (CaptureAll capture a :> api)) -> Router env # hoistServerWithContext :: Proxy (CaptureAll capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (CaptureAll capture a :> api) m -> ServerT (CaptureAll capture a :> api) n # | |
type MkLink (CaptureAll sym v :> sub :: *) a | |
Defined in Servant.Links | |
type ServerT (CaptureAll capture a :> api :: *) m | |
Defined in Servant.Server.Internal |
data BasicAuth (realm :: Symbol) userData #
Combinator for Basic Access Authentication.
- IMPORTANT*: Only use Basic Auth over HTTPS! Credentials are not hashed or encrypted. Note also that because the same credentials are sent on every request, Basic Auth is not as secure as some alternatives. Further, the implementation in servant-server does not protect against some types of timing attacks.
In Basic Auth, username and password are base64-encoded and transmitted via
the Authorization
header. Handshakes are not required, making it
relatively efficient.
Instances
HasLink sub => HasLink (BasicAuth realm a :> sub :: *) | |
(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api :: *) context | Basic Authentication |
Defined in Servant.Server.Internal route :: Proxy (BasicAuth realm usr :> api) -> Context context -> Delayed env (Server (BasicAuth realm usr :> api)) -> Router env # hoistServerWithContext :: Proxy (BasicAuth realm usr :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (BasicAuth realm usr :> api) m -> ServerT (BasicAuth realm usr :> api) n # | |
type MkLink (BasicAuth realm a :> sub :: *) r | |
type ServerT (BasicAuth realm usr :> api :: *) m | |
data BasicAuthData #
A simple datatype to hold data required to decorate a request
Union of two APIs, first takes precedence in case of overlap.
Example:
>>>
:{
type MyApi = "books" :> Get '[JSON] [Book] -- GET /books :<|> "books" :> ReqBody '[JSON] Book :> Post '[JSON] () -- POST /books :}
a :<|> b infixr 3 |
Instances
Functor ((:<|>) a) | |
Foldable ((:<|>) a) | |
Defined in Servant.API.Alternative fold :: Monoid m => (a :<|> m) -> m # foldMap :: Monoid m => (a0 -> m) -> (a :<|> a0) -> m # foldr :: (a0 -> b -> b) -> b -> (a :<|> a0) -> b # foldr' :: (a0 -> b -> b) -> b -> (a :<|> a0) -> b # foldl :: (b -> a0 -> b) -> b -> (a :<|> a0) -> b # foldl' :: (b -> a0 -> b) -> b -> (a :<|> a0) -> b # foldr1 :: (a0 -> a0 -> a0) -> (a :<|> a0) -> a0 # foldl1 :: (a0 -> a0 -> a0) -> (a :<|> a0) -> a0 # toList :: (a :<|> a0) -> [a0] # length :: (a :<|> a0) -> Int # elem :: Eq a0 => a0 -> (a :<|> a0) -> Bool # maximum :: Ord a0 => (a :<|> a0) -> a0 # minimum :: Ord a0 => (a :<|> a0) -> a0 # | |
Traversable ((:<|>) a) | |
(HasLink a, HasLink b) => HasLink (a :<|> b :: *) | |
(HasServer a context, HasServer b context) => HasServer (a :<|> b :: *) context | A server for 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 = ... |
(Bounded a, Bounded b) => Bounded (a :<|> b) | |
(Eq a, Eq b) => Eq (a :<|> b) | |
(Show a, Show b) => Show (a :<|> b) | |
(Semigroup a, Semigroup b) => Semigroup (a :<|> b) | |
(Monoid a, Monoid b) => Monoid (a :<|> b) | |
type MkLink (a :<|> b :: *) r | |
type ServerT (a :<|> b :: *) m | |
type Vault = Vault RealWorld #
A persistent store for values of arbitrary types.
This variant is the simplest and creates keys in the IO
monad.
See the module Data.Vault.ST if you want to use it with the ST
monad instead.
serveDirectory :: FilePath -> ServerT Raw m #
Same as serveDirectoryFileServer
. It used to be the only
file serving function in servant pre-0.10 and will be kept
around for a few versions, but is deprecated.
serveDirectoryWith :: StaticSettings -> ServerT Raw m #
Alias for staticApp
. Lets you serve a directory
with arbitrary StaticSettings
. Useful when you want
particular settings not covered by the four other
variants. This is the most flexible method.
serveDirectoryEmbedded :: [(FilePath, ByteString)] -> ServerT Raw m #
Uses embeddedSettings
.
serveDirectoryWebAppLookup :: ETagLookup -> FilePath -> ServerT Raw m #
Same as serveDirectoryWebApp
, but uses webAppSettingsWithLookup
.
serveDirectoryFileServer :: FilePath -> ServerT Raw m #
Same as serveDirectoryWebApp
, but uses defaultFileServerSettings
.
serveDirectoryWebApp :: FilePath -> ServerT Raw m #
Serve anything under the specified directory as a Raw
endpoint.
type MyApi = "static" :> Raw server :: Server MyApi server = serveDirectoryWebApp "/var/www"
would capture any request to /static/<something>
and look for
<something>
under /var/www
.
It will do its best to guess the MIME type for that file, based on the extension, and send an appropriate Content-Type header if possible.
If your goal is to serve HTML, CSS and Javascript files that use the rest of the API
as a webapp backend, you will most likely not want the static files to be hidden
behind a /static/ prefix. In that case, remember to put the serveDirectoryWebApp
handler in the last position, because servant will try to match the handlers
in order.
Corresponds to the defaultWebAppSettings
StaticSettings
value.
layout :: HasServer api ([] :: [*]) => Proxy api -> Text #
The function layout
produces a textual description of the internal
router layout for debugging purposes. Note that the router layout is
determined just by the API, not by the handlers.
Example:
For the following API
type API = "a" :> "d" :> Get '[JSON] NoContent :<|> "b" :> Capture "x" Int :> Get '[JSON] Bool :<|> "c" :> Put '[JSON] Bool :<|> "a" :> "e" :> Get '[JSON] Int :<|> "b" :> Capture "x" Int :> Put '[JSON] Bool :<|> Raw
we get the following output:
/ ├─ a/ │ ├─ d/ │ │ └─• │ └─ e/ │ └─• ├─ b/ │ └─ <capture>/ │ ├─• │ ┆ │ └─• ├─ c/ │ └─• ┆ └─ <raw>
Explanation of symbols:
├
- Normal lines reflect static branching via a table.
a/
- Nodes reflect static path components.
─•
- Leaves reflect endpoints.
<capture>/
- This is a delayed capture of a path component.
<raw>
- This is a part of the API we do not know anything about.
┆
- Dashed lines suggest a dynamic choice between the part above and below. If there is a success for fatal failure in the first part, that one takes precedence. If both parts fail, the "better" error code will be returned.
hoistServer :: HasServer api ([] :: [*]) => Proxy api -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n #
Hoist server implementation.
Sometimes our cherished Handler
monad isn't quite the type you'd like for
your handlers. Maybe you want to thread some configuration in a Reader
monad. Or have your types ensure that your handlers don't do any IO. Use
hoistServer
(a successor of now deprecated enter
).
With hoistServer
, you can provide a function,
to convert any number of endpoints from one type constructor to
another. For example
Note: Server
Raw
can also be entered. It will be retagged.
>>>
import Control.Monad.Reader
>>>
type ReaderAPI = "ep1" :> Get '[JSON] Int :<|> "ep2" :> Get '[JSON] String :<|> Raw :<|> EmptyAPI
>>>
let readerApi = Proxy :: Proxy ReaderAPI
>>>
let readerServer = return 1797 :<|> ask :<|> Tagged (error "raw server") :<|> emptyServer :: ServerT ReaderAPI (Reader String)
>>>
let nt x = return (runReader x "hi")
>>>
let mainServer = hoistServer readerApi nt readerServer :: Server ReaderAPI
serveWithContext :: HasServer api context => Proxy api -> Context context -> Server api -> Application #
serve :: HasServer api ([] :: [*]) => Proxy api -> Server api -> Application #
serve
allows you to implement an API and produce a wai Application
.
Example:
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 = ... myApi :: Proxy MyApi myApi = Proxy app :: Application app = serve myApi server main :: IO () main = Network.Wai.Handler.Warp.run 8080 app
emptyServer :: ServerT EmptyAPI m #
Server for EmptyAPI
class HasServer (api :: k) (context :: [*]) where #
route :: Proxy api -> Context context -> Delayed env (Server api) -> Router env #
hoistServerWithContext :: Proxy api -> Proxy context -> (forall x. m x -> n x) -> ServerT api m -> ServerT api n #
Instances
HasServer Raw context | Just pass the request to the underlying application and serve its response. Example: type MyApi = "images" :> Raw server :: Server MyApi server = serveDirectory "/var/www/images" |
HasServer EmptyAPI context | The server for an type MyApi = "nothing" :> EmptyApi server :: Server MyApi server = emptyAPIServer |
(TypeError (HasServerArrowTypeError a b) :: Constraint) => HasServer (a -> b :: *) context | This instance prevents from accidentally using '->' instead of
|
(HasServer a context, HasServer b context) => HasServer (a :<|> b :: *) context | A server for 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 = ... |
(HasContextEntry context (NamedContext name subContext), HasServer subApi subContext) => HasServer (WithNamedContext name subContext subApi :: *) context | |
Defined in Servant.Server.Internal type ServerT (WithNamedContext name subContext subApi) m :: * # route :: Proxy (WithNamedContext name subContext subApi) -> Context context -> Delayed env (Server (WithNamedContext name subContext subApi)) -> Router env # hoistServerWithContext :: Proxy (WithNamedContext name subContext subApi) -> Proxy context -> (forall x. m x -> n x) -> ServerT (WithNamedContext name subContext subApi) m -> ServerT (WithNamedContext name subContext subApi) n # | |
(TypeError (HasServerArrowKindError arr) :: Constraint) => HasServer (arr :> api :: *) context | This instance catches mistakes when there are non-saturated
type applications on LHS of
|
Defined in Servant.Server.Internal | |
HasServer api context => HasServer (HttpVersion :> api :: *) context | |
Defined in Servant.Server.Internal type ServerT (HttpVersion :> api) m :: * # route :: Proxy (HttpVersion :> api) -> Context context -> Delayed env (Server (HttpVersion :> api)) -> Router env # hoistServerWithContext :: Proxy (HttpVersion :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (HttpVersion :> api) m -> ServerT (HttpVersion :> api) n # | |
(AllCTUnrender list a, HasServer api context, SBoolI (FoldLenient mods)) => HasServer (ReqBody' mods list a :> api :: *) context | If you use All it asks is for a 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... |
Defined in Servant.Server.Internal route :: Proxy (ReqBody' mods list a :> api) -> Context context -> Delayed env (Server (ReqBody' mods list a :> api)) -> Router env # hoistServerWithContext :: Proxy (ReqBody' mods list a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (ReqBody' mods list a :> api) m -> ServerT (ReqBody' mods list a :> api) n # | |
HasServer api context => HasServer (RemoteHost :> api :: *) context | |
Defined in Servant.Server.Internal type ServerT (RemoteHost :> api) m :: * # route :: Proxy (RemoteHost :> api) -> Context context -> Delayed env (Server (RemoteHost :> api)) -> Router env # hoistServerWithContext :: Proxy (RemoteHost :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (RemoteHost :> api) m -> ServerT (RemoteHost :> api) n # | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => HasServer (QueryParam' mods sym a :> api :: *) context | If you use 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 You can control how it'll be converted from 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... |
Defined in Servant.Server.Internal type ServerT (QueryParam' mods sym a :> api) m :: * # route :: Proxy (QueryParam' mods sym a :> api) -> Context context -> Delayed env (Server (QueryParam' mods sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (QueryParam' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParam' mods sym a :> api) m -> ServerT (QueryParam' mods sym a :> api) n # | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context) => HasServer (QueryParams sym a :> api :: *) context | If you use This lets servant worry about looking up 0 or more values in the query string
associated to You can control how the individual values are converted from 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... |
Defined in Servant.Server.Internal type ServerT (QueryParams sym a :> api) m :: * # route :: Proxy (QueryParams sym a :> api) -> Context context -> Delayed env (Server (QueryParams sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (QueryParams sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (QueryParams sym a :> api) m -> ServerT (QueryParams sym a :> api) n # | |
(KnownSymbol sym, HasServer api context) => HasServer (QueryFlag sym :> api :: *) context | If you use 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... |
Defined in Servant.Server.Internal | |
(KnownSymbol sym, FromHttpApiData a, HasServer api context, SBoolI (FoldRequired mods), SBoolI (FoldLenient mods)) => HasServer (Header' mods sym a :> api :: *) context | If you use All it asks is for a 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 |
Defined in Servant.Server.Internal route :: Proxy (Header' mods sym a :> api) -> Context context -> Delayed env (Server (Header' mods sym a :> api)) -> Router env # hoistServerWithContext :: Proxy (Header' mods sym a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Header' mods sym a :> api) m -> ServerT (Header' mods sym a :> api) n # | |
HasServer api context => HasServer (IsSecure :> api :: *) context | |
Defined in Servant.Server.Internal | |
HasServer api ctx => HasServer (Summary desc :> api :: *) ctx | Ignore |
Defined in Servant.Server.Internal | |
HasServer api ctx => HasServer (Description desc :> api :: *) ctx | Ignore |
Defined in Servant.Server.Internal type ServerT (Description desc :> api) m :: * # route :: Proxy (Description desc :> api) -> Context ctx -> Delayed env (Server (Description desc :> api)) -> Router env # hoistServerWithContext :: Proxy (Description desc :> api) -> Proxy ctx -> (forall x. m x -> n x) -> ServerT (Description desc :> api) m -> ServerT (Description desc :> api) n # | |
(KnownSymbol capture, FromHttpApiData a, HasServer api context) => HasServer (Capture' mods capture a :> api :: *) context | If you use You can control how it'll be converted from Example: type MyApi = "books" :> Capture "isbn" Text :> Get '[JSON] Book server :: Server MyApi server = getBook where getBook :: Text -> Handler Book getBook isbn = ... |
Defined in Servant.Server.Internal route :: Proxy (Capture' mods capture a :> api) -> Context context -> Delayed env (Server (Capture' mods capture a :> api)) -> Router env # hoistServerWithContext :: Proxy (Capture' mods capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Capture' mods capture a :> api) m -> ServerT (Capture' mods capture a :> api) n # | |
(KnownSymbol capture, FromHttpApiData a, HasServer api context) => HasServer (CaptureAll capture a :> api :: *) context | If you use You can control how they'll be converted from Example: type MyApi = "src" :> CaptureAll "segments" Text :> Get '[JSON] SourceFile server :: Server MyApi server = getSourceFile where getSourceFile :: [Text] -> Handler Book getSourceFile pathSegments = ... |
Defined in Servant.Server.Internal type ServerT (CaptureAll capture a :> api) m :: * # route :: Proxy (CaptureAll capture a :> api) -> Context context -> Delayed env (Server (CaptureAll capture a :> api)) -> Router env # hoistServerWithContext :: Proxy (CaptureAll capture a :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (CaptureAll capture a :> api) m -> ServerT (CaptureAll capture a :> api) n # | |
(KnownSymbol realm, HasServer api context, HasContextEntry context (BasicAuthCheck usr)) => HasServer (BasicAuth realm usr :> api :: *) context | Basic Authentication |
Defined in Servant.Server.Internal route :: Proxy (BasicAuth realm usr :> api) -> Context context -> Delayed env (Server (BasicAuth realm usr :> api)) -> Router env # hoistServerWithContext :: Proxy (BasicAuth realm usr :> api) -> Proxy context -> (forall x. m x -> n x) -> ServerT (BasicAuth realm usr :> api) m -> ServerT (BasicAuth realm usr :> api) n # | |
HasServer api context => HasServer (Vault :> api :: *) context | |
Defined in Servant.Server.Internal | |
(KnownSymbol path, HasServer api context) => HasServer (path :> api :: *) context | Make sure the incoming request starts with |
Defined in Servant.Server.Internal | |
(AllCTRender ctypes a, ReflectMethod method, KnownNat status) => HasServer (Verb method status ctypes a :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Verb method status ctypes a) -> Context context -> Delayed env (Server (Verb method status ctypes a)) -> Router env # hoistServerWithContext :: Proxy (Verb method status ctypes a) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes a) m -> ServerT (Verb method status ctypes a) n # | |
(AllCTRender ctypes a, ReflectMethod method, KnownNat status, GetHeaders (Headers h a)) => HasServer (Verb method status ctypes (Headers h a) :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Verb method status ctypes (Headers h a)) -> Context context -> Delayed env (Server (Verb method status ctypes (Headers h a))) -> Router env # hoistServerWithContext :: Proxy (Verb method status ctypes (Headers h a)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Verb method status ctypes (Headers h a)) m -> ServerT (Verb method status ctypes (Headers h a)) n # | |
(MimeRender ctype a, ReflectMethod method, KnownNat status, FramingRender framing ctype, ToStreamGenerator b a) => HasServer (Stream method status framing ctype b :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Stream method status framing ctype b) -> Context context -> Delayed env (Server (Stream method status framing ctype b)) -> Router env # hoistServerWithContext :: Proxy (Stream method status framing ctype b) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype b) m -> ServerT (Stream method status framing ctype b) n # | |
(MimeRender ctype a, ReflectMethod method, KnownNat status, FramingRender framing ctype, ToStreamGenerator b a, GetHeaders (Headers h b)) => HasServer (Stream method status framing ctype (Headers h b) :: *) context | |
Defined in Servant.Server.Internal route :: Proxy (Stream method status framing ctype (Headers h b)) -> Context context -> Delayed env (Server (Stream method status framing ctype (Headers h b))) -> Router env # hoistServerWithContext :: Proxy (Stream method status framing ctype (Headers h b)) -> Proxy context -> (forall x. m x -> n x) -> ServerT (Stream method status framing ctype (Headers h b)) m -> ServerT (Stream method status framing ctype (Headers h b)) n # |
data EmptyServer #
Singleton type representing a server that serves an empty API.
Instances
Bounded EmptyServer | |
Defined in Servant.Server.Internal minBound :: EmptyServer # maxBound :: EmptyServer # | |
Enum EmptyServer | |
Defined in Servant.Server.Internal succ :: EmptyServer -> EmptyServer # pred :: EmptyServer -> EmptyServer # toEnum :: Int -> EmptyServer # fromEnum :: EmptyServer -> Int # enumFrom :: EmptyServer -> [EmptyServer] # enumFromThen :: EmptyServer -> EmptyServer -> [EmptyServer] # enumFromTo :: EmptyServer -> EmptyServer -> [EmptyServer] # enumFromThenTo :: EmptyServer -> EmptyServer -> EmptyServer -> [EmptyServer] # | |
Eq EmptyServer | |
Defined in Servant.Server.Internal (==) :: EmptyServer -> EmptyServer -> Bool # (/=) :: EmptyServer -> EmptyServer -> Bool # | |
Show EmptyServer | |
Defined in Servant.Server.Internal showsPrec :: Int -> EmptyServer -> ShowS # show :: EmptyServer -> String # showList :: [EmptyServer] -> ShowS # |
data BasicAuthResult usr #
servant-server's current implementation of basic authentication is not immune to certian kinds of timing attacks. Decoding payloads does not take a fixed amount of time.
The result of authentication/authorization
Instances
newtype BasicAuthCheck usr #
Datatype wrapping a function used to check authentication.
BasicAuthCheck | |
|
Instances
Functor BasicAuthCheck | |
Defined in Servant.Server.Internal.BasicAuth fmap :: (a -> b) -> BasicAuthCheck a -> BasicAuthCheck b # (<$) :: a -> BasicAuthCheck b -> BasicAuthCheck a # | |
Generic (BasicAuthCheck usr) | |
Defined in Servant.Server.Internal.BasicAuth type Rep (BasicAuthCheck usr) :: * -> * # from :: BasicAuthCheck usr -> Rep (BasicAuthCheck usr) x # to :: Rep (BasicAuthCheck usr) x -> BasicAuthCheck usr # | |
type Rep (BasicAuthCheck usr) | |
Defined in Servant.Server.Internal.BasicAuth type Rep (BasicAuthCheck usr) = D1 (MetaData "BasicAuthCheck" "Servant.Server.Internal.BasicAuth" "servant-server-0.14.1-8QeZlk3HyJYB7GKYC8rKfC" True) (C1 (MetaCons "BasicAuthCheck" PrefixI True) (S1 (MetaSel (Just "unBasicAuthCheck") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (BasicAuthData -> IO (BasicAuthResult usr))))) |
tweakResponse :: (RouteResult Response -> RouteResult Response) -> Router env -> Router env #
Apply a transformation to the response of a Router
.
runHandler :: Handler a -> IO (Either ServantErr a) #
runHandler' :: Handler a -> ExceptT ServantErr IO a #
err505 :: ServantErr #
err505
HTTP Version not supported
Example usage:
failingHandler :: Handler () failingHandler = throwError $ err505 { errBody = "I support HTTP/4.0 only." }
err504 :: ServantErr #
err504
Gateway Time-out
Example:
failingHandler :: Handler () failingHandler = throwError $ err504 { errBody = "Backend foobar did not respond in 5 seconds." }
err503 :: ServantErr #
err503
Service Unavailable
Example:
failingHandler :: Handler () failingHandler = throwError $ err503 { errBody = "We're rewriting in PHP." }
err502 :: ServantErr #
err502
Bad Gateway
Example:
failingHandler :: Handler () failingHandler = throwError $ err502 { errBody = "Tried gateway foo, bar, and baz. None responded." }
err501 :: ServantErr #
err501
Not Implemented
Example:
failingHandler :: Handler () failingHandler = throwError $ err501 { errBody = "/v1/foo is not supported with quux in the request." }
err500 :: ServantErr #
err500
Internal Server Error
Example:
failingHandler :: Handler () failingHandler = throwError $ err500 { errBody = "Exception in module A.B.C:55. Have a great day!" }
err422 :: ServantErr #
err422
Unprocessable Entity
Example:
failingHandler :: Handler () failingHandler = throwError $ err422 { errBody = "I understood your request, but can't process it." }
err418 :: ServantErr #
err418
Expectation Failed
Example:
failingHandler :: Handler () failingHandler = throwError $ err418 { errBody = "Apologies, this is not a webserver but a teapot." }
err417 :: ServantErr #
err417
Expectation Failed
Example:
failingHandler :: Handler () failingHandler = throwError $ err417 { errBody = "I found a quux in the request. This isn't going to work." }
err416 :: ServantErr #
err416
Request range not satisfiable
Example:
failingHandler :: Handler () failingHandler = throwError $ err416 { errBody = "Valid range is [0, 424242]." }
err415 :: ServantErr #
err415
Unsupported Media Type
Example:
failingHandler :: Handler () failingHandler = throwError $ err415 { errBody = "Supported media types: gif, png" }
err414 :: ServantErr #
err414
Request-URI Too Large
Example:
failingHandler :: Handler () failingHandler = throwError $ err414 { errBody = "Maximum length is 64." }
err413 :: ServantErr #
err413
Request Entity Too Large
Example:
failingHandler :: Handler () failingHandler = throwError $ err413 { errBody = "Request exceeded 64k." }
err412 :: ServantErr #
err412
Precondition Failed
Example:
failingHandler :: Handler () failingHandler = throwError $ err412 { errBody = "Precondition fail: x < 42 && y > 57" }
err411 :: ServantErr #
err410 :: ServantErr #
err410
Gone
Example:
failingHandler :: Handler () failingHandler = throwError $ err410 { errBody = "I know it was here at some point, but.. I blame bad luck." }
err409 :: ServantErr #
err409
Conflict
Example:
failingHandler :: Handler () failingHandler = throwError $ err409 { errBody = "Transaction conflicts with 59879cb56c7c159231eeacdd503d755f7e835f74" }
err407 :: ServantErr #
err407
Proxy Authentication Required
Example:
failingHandler :: Handler () failingHandler = throwError err407
err406 :: ServantErr #
err405 :: ServantErr #
err405
Method Not Allowed
Example:
failingHandler :: Handler () failingHandler = throwError $ err405 { errBody = "Your account privileges does not allow for this. Please pay $$$." }
err404 :: ServantErr #
err404
Not Found
Example:
failingHandler :: Handler () failingHandler = throwError $ err404 { errBody = "(╯°□°)╯︵ ┻━┻)." }
err403 :: ServantErr #
err403
Forbidden
Example:
failingHandler :: Handler () failingHandler = throwError $ err403 { errBody = "Please login first." }
err402 :: ServantErr #
err402
Payment Required
Example:
failingHandler :: Handler () failingHandler = throwError $ err402 { errBody = "You have 0 credits. Please give me $$$." }
err401 :: ServantErr #
err401
Unauthorized
Example:
failingHandler :: Handler () failingHandler = throwError $ err401 { errBody = "Your credentials are invalid." }
err400 :: ServantErr #
err400
Bad Request
Example:
failingHandler :: Handler () failingHandler = throwError $ err400 { errBody = "Your request makes no sense to me." }
err307 :: ServantErr #
err305 :: ServantErr #
err304 :: ServantErr #
err303 :: ServantErr #
err302 :: ServantErr #
err301 :: ServantErr #
err300 :: ServantErr #
err300
Multiple Choices
Example:
failingHandler :: Handler () failingHandler = throwError $ err300 { errBody = "I can't choose." }
data ServantErr #
ServantErr | |
|
Instances
Eq ServantErr | |
Defined in Servant.Server.Internal.ServantErr (==) :: ServantErr -> ServantErr -> Bool # (/=) :: ServantErr -> ServantErr -> Bool # | |
Read ServantErr | |
Defined in Servant.Server.Internal.ServantErr readsPrec :: Int -> ReadS ServantErr # readList :: ReadS [ServantErr] # readPrec :: ReadPrec ServantErr # readListPrec :: ReadPrec [ServantErr] # | |
Show ServantErr | |
Defined in Servant.Server.Internal.ServantErr showsPrec :: Int -> ServantErr -> ShowS # show :: ServantErr -> String # showList :: [ServantErr] -> ShowS # | |
Exception ServantErr | |
Defined in Servant.Server.Internal.ServantErr toException :: ServantErr -> SomeException # fromException :: SomeException -> Maybe ServantErr # displayException :: ServantErr -> String # | |
MonadError ServantErr Handler | |
Defined in Servant.Server.Internal.Handler throwError :: ServantErr -> Handler a # catchError :: Handler a -> (ServantErr -> Handler a) -> Handler a # |
descendIntoNamedContext :: HasContextEntry context (NamedContext name subContext) => Proxy name -> Context context -> Context subContext #
descendIntoNamedContext
allows you to access NamedContext
s. Usually you
won't have to use it yourself but instead use a combinator like
WithNamedContext
.
This is how descendIntoNamedContext
works:
>>>
:set -XFlexibleContexts
>>>
let subContext = True :. EmptyContext
>>>
:type subContext
subContext :: Context '[Bool]>>>
let parentContext = False :. (NamedContext subContext :: NamedContext "subContext" '[Bool]) :. EmptyContext
>>>
:type parentContext
parentContext :: Context '[Bool, NamedContext "subContext" '[Bool]]>>>
descendIntoNamedContext (Proxy :: Proxy "subContext") parentContext :: Context '[Bool]
True :. EmptyContext
data Context (contextTypes :: [*]) where #
Context
s are used to pass values to combinators. (They are not meant
to be used to pass parameters to your handlers, i.e. they should not replace
any custom ReaderT
-monad-stack that you're using
with hoistServer
.) If you don't use combinators that
require any context entries, you can just use serve
as always.
If you are using combinators that require a non-empty Context
you have to
use serveWithContext
and pass it a Context
that contains all
the values your combinators need. A Context
is essentially a heterogenous
list and accessing the elements is being done by type (see getContextEntry
).
The parameter of the type Context
is a type-level list reflecting the types
of the contained context entries. To create a Context
with entries, use the
operator (
::.
)
>>>
:type True :. () :. EmptyContext
True :. () :. EmptyContext :: Context '[Bool, ()]
EmptyContext :: Context ([] :: [*]) | |
(:.) :: Context (x ': xs) infixr 5 |
class HasContextEntry (context :: [*]) val where #
This class is used to access context entries in Context
s. getContextEntry
returns the first value where the type matches:
>>>
getContextEntry (True :. False :. EmptyContext) :: Bool
True
If the Context
does not contain an entry of the requested type, you'll get
an error:
>>>
getContextEntry (True :. False :. EmptyContext) :: String
... ...No instance for (HasContextEntry '[] [Char]) ...
getContextEntry :: Context context -> val #
Instances
HasContextEntry xs val => HasContextEntry (notIt ': xs) val | |
Defined in Servant.Server.Internal.Context getContextEntry :: Context (notIt ': xs) -> val # | |
HasContextEntry (val ': xs) val | |
Defined in Servant.Server.Internal.Context getContextEntry :: Context (val ': xs) -> val # |
data NamedContext (name :: Symbol) (subContext :: [*]) #
Normally context entries are accessed by their types. In case you need
to have multiple values of the same type in your Context
and need to access
them, we provide NamedContext
. You can think of it as sub-namespaces for
Context
s.
NamedContext (Context subContext) |
type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived #
The WAI application.
Note that, since WAI 3.0, this type is structured in continuation passing
style to allow for proper safe resource handling. This was handled in the
past via other means (e.g., ResourceT
). As a demonstration:
app :: Application app req respond = bracket_ (putStrLn "Allocating scarce resource") (putStrLn "Cleaning up") (respond $ responseLBS status200 [] "Hello World")
newtype Tagged (s :: k) b :: forall k. k -> * -> * #
A
value is a value Tagged
s bb
with an attached phantom type s
.
This can be used in place of the more traditional but less safe idiom of
passing in an undefined value with the type, because unlike an (s -> b)
,
a
can't try to use the argument Tagged
s bs
as a real value.
Moreover, you don't have to rely on the compiler to inline away the extra argument, because the newtype is "free"
Tagged
has kind k -> * -> *
if the compiler supports PolyKinds
, therefore
there is an extra k
showing in the instance haddocks that may cause confusion.
Instances
ToJSON2 (Tagged :: * -> * -> *) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> Tagged a b -> Value # liftToJSONList2 :: (a -> Value) -> ([a] -> Value) -> (b -> Value) -> ([b] -> Value) -> [Tagged a b] -> Value # liftToEncoding2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> Tagged a b -> Encoding # liftToEncodingList2 :: (a -> Encoding) -> ([a] -> Encoding) -> (b -> Encoding) -> ([b] -> Encoding) -> [Tagged a b] -> Encoding # | |
FromJSON2 (Tagged :: * -> * -> *) | |
Defined in Data.Aeson.Types.FromJSON | |
Bitraversable (Tagged :: * -> * -> *) | |
Defined in Data.Tagged bitraverse :: Applicative f => (a -> f c) -> (b -> f d) -> Tagged a b -> f (Tagged c d) # | |
Bifoldable (Tagged :: * -> * -> *) | |
Bifunctor (Tagged :: * -> * -> *) | |
Eq2 (Tagged :: * -> * -> *) | |
Ord2 (Tagged :: * -> * -> *) | |
Defined in Data.Tagged | |
Read2 (Tagged :: * -> * -> *) | |
Defined in Data.Tagged liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (Tagged a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [Tagged a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (Tagged a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [Tagged a b] # | |
Show2 (Tagged :: * -> * -> *) | |
Generic1 (Tagged s :: * -> *) | |
Monad (Tagged s) | |
Functor (Tagged s) | |
Applicative (Tagged s) | |
Foldable (Tagged s) | |
Defined in Data.Tagged fold :: Monoid m => Tagged s m -> m # foldMap :: Monoid m => (a -> m) -> Tagged s a -> m # foldr :: (a -> b -> b) -> b -> Tagged s a -> b # foldr' :: (a -> b -> b) -> b -> Tagged s a -> b # foldl :: (b -> a -> b) -> b -> Tagged s a -> b # foldl' :: (b -> a -> b) -> b -> Tagged s a -> b # foldr1 :: (a -> a -> a) -> Tagged s a -> a # foldl1 :: (a -> a -> a) -> Tagged s a -> a # elem :: Eq a => a -> Tagged s a -> Bool # maximum :: Ord a => Tagged s a -> a # minimum :: Ord a => Tagged s a -> a # | |
Traversable (Tagged s) | |
ToJSON1 (Tagged a) | |
Defined in Data.Aeson.Types.ToJSON liftToJSON :: (a0 -> Value) -> ([a0] -> Value) -> Tagged a a0 -> Value # liftToJSONList :: (a0 -> Value) -> ([a0] -> Value) -> [Tagged a a0] -> Value # liftToEncoding :: (a0 -> Encoding) -> ([a0] -> Encoding) -> Tagged a a0 -> Encoding # liftToEncodingList :: (a0 -> Encoding) -> ([a0] -> Encoding) -> [Tagged a a0] -> Encoding # | |
FromJSON1 (Tagged a) | |
Eq1 (Tagged s) | |
Ord1 (Tagged s) | |
Defined in Data.Tagged | |
Read1 (Tagged s) | |
Defined in Data.Tagged | |
Show1 (Tagged s) | |
Bounded b => Bounded (Tagged s b) | |
Enum a => Enum (Tagged s a) | |
Defined in Data.Tagged succ :: Tagged s a -> Tagged s a # pred :: Tagged s a -> Tagged s a # fromEnum :: Tagged s a -> Int # enumFrom :: Tagged s a -> [Tagged s a] # enumFromThen :: Tagged s a -> Tagged s a -> [Tagged s a] # enumFromTo :: Tagged s a -> Tagged s a -> [Tagged s a] # enumFromThenTo :: Tagged s a -> Tagged s a -> Tagged s a -> [Tagged s a] # | |
Eq b => Eq (Tagged s b) | |
Floating a => Floating (Tagged s a) | |
Defined in Data.Tagged exp :: Tagged s a -> Tagged s a # log :: Tagged s a -> Tagged s a # sqrt :: Tagged s a -> Tagged s a # (**) :: Tagged s a -> Tagged s a -> Tagged s a # logBase :: Tagged s a -> Tagged s a -> Tagged s a # sin :: Tagged s a -> Tagged s a # cos :: Tagged s a -> Tagged s a # tan :: Tagged s a -> Tagged s a # asin :: Tagged s a -> Tagged s a # acos :: Tagged s a -> Tagged s a # atan :: Tagged s a -> Tagged s a # sinh :: Tagged s a -> Tagged s a # cosh :: Tagged s a -> Tagged s a # tanh :: Tagged s a -> Tagged s a # asinh :: Tagged s a -> Tagged s a # acosh :: Tagged s a -> Tagged s a # atanh :: Tagged s a -> Tagged s a # log1p :: Tagged s a -> Tagged s a # expm1 :: Tagged s a -> Tagged s a # | |
Fractional a => Fractional (Tagged s a) | |
Integral a => Integral (Tagged s a) | |
Defined in Data.Tagged quot :: Tagged s a -> Tagged s a -> Tagged s a # rem :: Tagged s a -> Tagged s a -> Tagged s a # div :: Tagged s a -> Tagged s a -> Tagged s a # mod :: Tagged s a -> Tagged s a -> Tagged s a # quotRem :: Tagged s a -> Tagged s a -> (Tagged s a, Tagged s a) # divMod :: Tagged s a -> Tagged s a -> (Tagged s a, Tagged s a) # | |
(Data s, Data b) => Data (Tagged s b) | |
Defined in Data.Tagged gfoldl :: (forall d b0. Data d => c (d -> b0) -> d -> c b0) -> (forall g. g -> c g) -> Tagged s b -> c (Tagged s b) # gunfold :: (forall b0 r. Data b0 => c (b0 -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Tagged s b) # toConstr :: Tagged s b -> Constr # dataTypeOf :: Tagged s b -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Tagged s b)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Tagged s b)) # gmapT :: (forall b0. Data b0 => b0 -> b0) -> Tagged s b -> Tagged s b # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Tagged s b -> r # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Tagged s b -> r # gmapQ :: (forall d. Data d => d -> u) -> Tagged s b -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Tagged s b -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Tagged s b -> m (Tagged s b) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Tagged s b -> m (Tagged s b) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Tagged s b -> m (Tagged s b) # | |
Num a => Num (Tagged s a) | |
Defined in Data.Tagged | |
Ord b => Ord (Tagged s b) | |
Read b => Read (Tagged s b) | |
Real a => Real (Tagged s a) | |
Defined in Data.Tagged toRational :: Tagged s a -> Rational # | |
RealFloat a => RealFloat (Tagged s a) | |
Defined in Data.Tagged floatRadix :: Tagged s a -> Integer # floatDigits :: Tagged s a -> Int # floatRange :: Tagged s a -> (Int, Int) # decodeFloat :: Tagged s a -> (Integer, Int) # encodeFloat :: Integer -> Int -> Tagged s a # exponent :: Tagged s a -> Int # significand :: Tagged s a -> Tagged s a # scaleFloat :: Int -> Tagged s a -> Tagged s a # isInfinite :: Tagged s a -> Bool # isDenormalized :: Tagged s a -> Bool # isNegativeZero :: Tagged s a -> Bool # | |
RealFrac a => RealFrac (Tagged s a) | |
Show b => Show (Tagged s b) | |
Ix b => Ix (Tagged s b) | |
Defined in Data.Tagged range :: (Tagged s b, Tagged s b) -> [Tagged s b] # index :: (Tagged s b, Tagged s b) -> Tagged s b -> Int # unsafeIndex :: (Tagged s b, Tagged s b) -> Tagged s b -> Int inRange :: (Tagged s b, Tagged s b) -> Tagged s b -> Bool # rangeSize :: (Tagged s b, Tagged s b) -> Int # unsafeRangeSize :: (Tagged s b, Tagged s b) -> Int | |
IsString a => IsString (Tagged s a) | |
Defined in Data.Tagged fromString :: String -> Tagged s a # | |
Generic (Tagged s b) | |
Semigroup a => Semigroup (Tagged s a) | |
(Semigroup a, Monoid a) => Monoid (Tagged s a) | |
ToJSON b => ToJSON (Tagged a b) | |
Defined in Data.Aeson.Types.ToJSON | |
ToJSONKey b => ToJSONKey (Tagged a b) | |
Defined in Data.Aeson.Types.ToJSON toJSONKey :: ToJSONKeyFunction (Tagged a b) # toJSONKeyList :: ToJSONKeyFunction [Tagged a b] # | |
FromJSON b => FromJSON (Tagged a b) | |
FromJSONKey b => FromJSONKey (Tagged a b) | |
Defined in Data.Aeson.Types.FromJSON fromJSONKey :: FromJSONKeyFunction (Tagged a b) # fromJSONKeyList :: FromJSONKeyFunction [Tagged a b] # | |
Storable a => Storable (Tagged s a) | |
Defined in Data.Tagged | |
Bits a => Bits (Tagged s a) | |
Defined in Data.Tagged (.&.) :: Tagged s a -> Tagged s a -> Tagged s a # (.|.) :: Tagged s a -> Tagged s a -> Tagged s a # xor :: Tagged s a -> Tagged s a -> Tagged s a # complement :: Tagged s a -> Tagged s a # shift :: Tagged s a -> Int -> Tagged s a # rotate :: Tagged s a -> Int -> Tagged s a # setBit :: Tagged s a -> Int -> Tagged s a # clearBit :: Tagged s a -> Int -> Tagged s a # complementBit :: Tagged s a -> Int -> Tagged s a # testBit :: Tagged s a -> Int -> Bool # bitSizeMaybe :: Tagged s a -> Maybe Int # bitSize :: Tagged s a -> Int # isSigned :: Tagged s a -> Bool # shiftL :: Tagged s a -> Int -> Tagged s a # unsafeShiftL :: Tagged s a -> Int -> Tagged s a # shiftR :: Tagged s a -> Int -> Tagged s a # unsafeShiftR :: Tagged s a -> Int -> Tagged s a # rotateL :: Tagged s a -> Int -> Tagged s a # | |
FiniteBits a => FiniteBits (Tagged s a) | |
Defined in Data.Tagged finiteBitSize :: Tagged s a -> Int # countLeadingZeros :: Tagged s a -> Int # countTrailingZeros :: Tagged s a -> Int # | |
NFData b => NFData (Tagged s b) | |
Defined in Data.Tagged | |
type Rep1 (Tagged s :: * -> *) | |
Defined in Data.Tagged | |
type Rep (Tagged s b) | |
Defined in Data.Tagged |
splitOn :: Eq a => [a] -> [a] -> [[a]] #
Split on the given sublist. Equivalent to
. For example:split
. dropDelims
. onSublist
splitOn ".." "a..b...c....d.." == ["a","b",".c","","d",""]
In some parsing combinator frameworks this is also known as
sepBy
.
Note that this is the right inverse of the intercalate
function
from Data.List, that is,
intercalate x . splitOn x === id
is the identity on
certain lists, but it is tricky to state the precise conditions
under which this holds. (For example, it is not enough to say
that splitOn
x . intercalate
xx
does not occur in any elements of the input list.
Working out why is left as an exercise for the reader.)
fromLT :: ConvertibleStrings LT a => LT -> a #
fromLazyText :: ConvertibleStrings LazyText a => LazyText -> a #
fromST :: ConvertibleStrings ST a => ST -> a #
fromStrictText :: ConvertibleStrings StrictText a => StrictText -> a #
fromLBS :: ConvertibleStrings LBS a => LBS -> a #
fromLazyByteString :: ConvertibleStrings LazyByteString a => LazyByteString -> a #
fromSBS :: ConvertibleStrings SBS a => SBS -> a #
toLT :: ConvertibleStrings a LT => a -> LT #
toLazyText :: ConvertibleStrings a LazyText => a -> LazyText #
toST :: ConvertibleStrings a ST => a -> ST #
toStrictText :: ConvertibleStrings a StrictText => a -> StrictText #
toLBS :: ConvertibleStrings a LBS => a -> LBS #
toLazyByteString :: ConvertibleStrings a LazyByteString => a -> LazyByteString #
toSBS :: ConvertibleStrings a SBS => a -> SBS #
toString :: ConvertibleStrings a String => a -> String #
cs :: ConvertibleStrings a b => a -> b #
class ConvertibleStrings a b where #
convertString :: a -> b #
Instances
type StrictByteString = ByteString #
type SBS = ByteString #
type LazyByteString = ByteString #
type LBS = ByteString #
type StrictText = Text #
exceptToMaybeT :: Functor m => ExceptT e m a -> MaybeT m a #
maybeToExceptT :: Functor m => e -> MaybeT m a -> ExceptT e m a #
mkWeakThreadId :: MonadIO m => ThreadId -> m (Weak ThreadId) #
Lifted version of mkWeakThreadId
.
Since: unliftio-0.1.1.0
runInUnboundThread :: MonadUnliftIO m => m a -> m a #
Unlifted version of runInUnboundThread
.
Since: unliftio-0.1.1.0
runInBoundThread :: MonadUnliftIO m => m a -> m a #
Unlifted version of runInBoundThread
.
Since: unliftio-0.1.1.0
forkOS :: MonadUnliftIO m => m () -> m ThreadId #
Unflifted version of forkOS
.
Since: unliftio-0.1.1.0
threadCapability :: MonadIO m => ThreadId -> m (Int, Bool) #
Lifted version of threadCapability
.
Since: unliftio-0.1.1.0
setNumCapabilities :: MonadIO m => Int -> m () #
Lifted version of setNumCapabilities
.
Since: unliftio-0.1.1.0
getNumCapabilities :: MonadIO m => m Int #
Lifted version of getNumCapabilities
.
Since: unliftio-0.1.1.0
forkOnWithUnmask :: MonadUnliftIO m => Int -> ((forall a. m a -> m a) -> m ()) -> m ThreadId #
Unlifted version of forkOnWithUnmask
.
Since: unliftio-0.1.1.0
forkOn :: MonadUnliftIO m => Int -> m () -> m ThreadId #
Unlifted version of forkOn
.
Since: unliftio-0.1.1.0
killThread :: MonadIO m => ThreadId -> m () #
Lifted version of killThread
.
Since: unliftio-0.1.1.0
forkFinally :: MonadUnliftIO m => m a -> (Either SomeException a -> m ()) -> m ThreadId #
Unlifted version of forkFinally
.
Since: unliftio-0.1.1.0
forkWithUnmask :: MonadUnliftIO m => ((forall a. m a -> m a) -> m ()) -> m ThreadId #
Unlifted version of forkIOWithUnmask
.
Since: unliftio-0.1.1.0
forkIO :: MonadUnliftIO m => m () -> m ThreadId #
Unlifted version of forkIO
.
Since: unliftio-0.1.1.0
type Middleware = Application -> Application #
Middleware is a component that sits between the server and application. It can do such tasks as GZIP encoding or response caching. What follows is the general definition of middleware, though a middleware author should feel free to modify this.
As an example of an alternate type for middleware, suppose you write a function to load up session information. The session information is simply a string map \[(String, String)\]. A logical type signature for this middleware might be:
loadSession :: ([(String, String)] -> Application) -> Application
Here, instead of taking a standard Application
as its first argument, the
middleware takes a function which consumes the session information as well.
defWaiMain :: Application -> IO () #
defPutListening :: WaiOptions -> IO () #
waiMain :: (WaiOptions -> IO ()) -> (WaiOptions -> IO ()) -> Application -> IO () #
runGraceful :: GracefulMode -> (Settings -> Application -> IO ()) -> Settings -> Application -> IO () #
runActivated :: (Settings -> Socket -> Application -> IO ()) -> Settings -> Application -> IO () #
data WaiOptions #
Instances
Options WaiOptions | |
Defined in Network.Wai.Cli |
metrics :: WaiMetrics -> Middleware #
Create a middleware to be added to a WAI-based webserver.
registerNamedWaiMetrics :: Text -> Store -> IO WaiMetrics #
Register in EKG a number of metrics related to web server activity with a namespace.
registerWaiMetrics :: Store -> IO WaiMetrics #
Register in EKG a number of metrics related to web server activity using empty namespace.
wai.request_count
wai.response_status_1xx
wai.response_status_2xx
wai.response_status_3xx
wai.response_status_4xx
wai.response_status_5xx
wai.latency_distribution
data WaiMetrics #
The metrics to feed in WAI and register in EKG.
runMagicbaneHandler :: β -> RIO β α -> Handler α Source #
magicbaneApp :: forall β χ ψ. HasServer χ ψ => Proxy χ -> Context ψ -> β -> ServerT χ (RIO β) -> Application Source #
Constructs a WAI application from an API definition, a Servant context (used for auth mainly), the app context and the actual action handlers.
type Formatter = TimedFastLogger -> CallStack -> LogSource -> LogLevel -> Utf8Builder -> IO () Source #
newLogger :: LogType -> Formatter -> IO (TimedFastLogger, ModLogger) Source #
Creates a logger module using a given formatting function. | Also returns the underlying TimedFastLogger for use outside of your Magicbane app (e.g. in some WAI middleware).
newtype ModMetrics Source #
forkMetricsServer :: ByteString -> Int -> IO Server Source #
newMetricsWith :: Store -> IO ModMetrics Source #
Creates a metrics module with a particular Store. The Store should come from the backend you want to use for storing the metrics. For development, a simple backend that shows metrics on a web page is ekg-wai, reexported here.
mergeVal :: Value -> Value -> Value Source #
Merges two JSON objects recursively. When the values are not objects, just returns the left one.
writeForm :: (ConvertibleStrings α Text, ConvertibleStrings β Text, ConvertibleStrings ByteString γ) => [(α, β)] -> γ Source #
Encodes key-value data as application/x-www-form-urlencoded.
readForm :: (ConvertibleStrings Text α, ConvertibleStrings Text β, ConvertibleStrings γ ByteString) => γ -> Maybe [(α, β)] Source #
Decodes key-value data from application/x-www-form-urlencoded.
formList :: Form -> [(Text, Text)] Source #
Reads a Servant incoming form as a list of key-value pairs (for use in FromForm instances).
formToObject :: [(Text, Text)] -> Value Source #
Converts a flat key-value form with keys in typical nesting syntax (e.g. "one[two][three]") to an Aeson Value with nesting (for use in FromForm instances).
slugify :: Text -> Text Source #
Prepares text for inclusion in a URL.
>>>
:set -XOverloadedStrings
>>>
slugify "Hello & World!"
"hello-and-world"
errText :: ServantErr -> ByteString -> ServantErr Source #
Creates a simple text/plain ServantErr.
throwErrText :: MonadThrow μ => ServantErr -> ByteString -> μ α Source #
Creates and throws a simple text/plain ServantErr.
type MonadHTTP ψ μ = (HasHttpManager ψ, MonadReader ψ μ, MonadUnliftIO μ) Source #
newtype ModHttpClient Source #
reqS :: (MonadHTTP ψ μ, ConvertibleStrings σ String) => σ -> ExceptT Text μ Request Source #
Creates a request from a string of any type, parsing it into a URI.
anyStatus :: MonadHTTP ψ μ => Request -> ExceptT Text μ Request Source #
Configures the request to not throw errors on error status codes.
postForm :: MonadHTTP ψ μ => [(Text, Text)] -> Request -> ExceptT Text μ Request Source #
Sets a x-www-form-urlencoded form as the request body (also sets the content-type).
postJson :: (MonadHTTP ψ μ, ToJSON α) => α -> Request -> ExceptT Text μ Request Source #
Sets a JSON value as the request body (via ToJSON; also sets the content-type).
performWithFn :: (MonadHTTP ψ μ, MonadCatch μ) => (ConduitM ι ByteString μ () -> ConduitT () Void μ ρ) -> Request -> ExceptT Text μ (Response ρ) Source #
Performs the request, using a given function to read the body. This is what all other performWith functions are based on.
performWithVoid :: (MonadHTTP ψ μ, MonadCatch μ) => Request -> ExceptT Text μ (Response ()) Source #
Performs the request, ignoring the body.
performWithBytes :: (MonadHTTP ψ μ, MonadCatch μ) => Request -> ExceptT Text μ (Response ByteString) Source #
Performs the request, reading the body into a lazy ByteString.
applyHeaders :: RequestHeaders -> Request -> Request Source #
Add headers to the request, preserving any existing headers not specified in the new set.
removeHeaders :: [HeaderName] -> Request -> Request Source #
Remove listed headers from the request.
askObj :: (Has β α, MonadReader α μ) => μ β Source #
Gets a value of any type from the context.
askOpt :: (Has β α, MonadReader α μ) => (β -> ψ) -> μ ψ Source #
Gets a thing from a value of any type from the context. (Useful for configuration fields.)
withEnvConfig :: FromEnv α => (α -> IO ()) -> IO () Source #
Reads an Envy configuration from the env variables and launches the given action if successful. (Does environment variable reading ever fail in practice? Probably not.)
type BasicApp α = RIO BasicContext α Source #
type BasicContext = (ModHttpClient, ModLogger) Source #