| Safe Haskell | Safe |
|---|---|
| Language | Haskell2010 |
Servant.API.Stream
Synopsis
- data Stream (method :: k1) (status :: Nat) (framing :: *) (contentType :: *) (a :: *)
- 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 a where
- data BoundaryStrategy
- data ByteStringParser a = ByteStringParser {
- parseIncremental :: ByteString -> Maybe (a, ByteString)
- parseEOF :: ByteString -> (a, ByteString)
- class FramingUnrender strategy a where
- data NoFraming
- data NewlineFraming
- data NetstringFraming
Documentation
data Stream (method :: k1) (status :: Nat) (framing :: *) (contentType :: *) (a :: *) #
A Stream endpoint for a given method emits a stream of encoded values at a given Content-Type, delimited by a framing strategy. Stream endpoints always return response code 200 on success. Type synonyms are provided for standard methods.
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).
Constructors
| StreamGenerator | |
Fields
| |
Instances
| ToStreamGenerator (StreamGenerator a) a # | |
Defined in Servant.API.Stream Methods 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.
Minimal complete definition
Methods
toStreamGenerator :: a -> StreamGenerator b #
Instances
| ToStreamGenerator (StreamGenerator a) a # | |
Defined in Servant.API.Stream Methods 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 Methods 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.
Minimal complete definition
Methods
buildFromStream :: ResultStream a -> b #
Instances
| BuildFromStream a (ResultStream a) # | |
Defined in Servant.API.Stream Methods buildFromStream :: ResultStream a -> ResultStream a # | |
class FramingRender strategy a 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.
Methods
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 Methods 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 Methods 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.
Constructors
| ByteStringParser | |
Fields
| |
class FramingUnrender strategy a 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.
Minimal complete definition
Methods
unrenderFrames :: Proxy strategy -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) #
Instances
| FramingUnrender NoFraming (a :: k) # | |
Defined in Servant.API.Stream Methods unrenderFrames :: Proxy NoFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
| FramingUnrender NewlineFraming (a :: k) # | |
Defined in Servant.API.Stream Methods unrenderFrames :: Proxy NewlineFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
| FramingUnrender NetstringFraming (a :: k) # | |
Defined in Servant.API.Stream Methods 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
| FramingUnrender NoFraming (a :: k) # | |
Defined in Servant.API.Stream Methods unrenderFrames :: Proxy NoFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
| FramingRender NoFraming (a :: k) # | |
Defined in Servant.API.Stream | |
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
| FramingUnrender NewlineFraming (a :: k) # | |
Defined in Servant.API.Stream Methods unrenderFrames :: Proxy NewlineFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
| FramingRender NewlineFraming (a :: k) # | |
Defined in Servant.API.Stream Methods header :: Proxy NewlineFraming -> Proxy a -> ByteString # boundary :: Proxy NewlineFraming -> Proxy a -> BoundaryStrategy # trailer :: Proxy NewlineFraming -> Proxy a -> ByteString # | |
data NetstringFraming #
The netstring framing strategy as defined by djb: http://cr.yp.to/proto/netstrings.txt
Instances
| FramingUnrender NetstringFraming (a :: k) # | |
Defined in Servant.API.Stream Methods unrenderFrames :: Proxy NetstringFraming -> Proxy a -> ByteStringParser (ByteStringParser (Either String ByteString)) # | |
| FramingRender NetstringFraming (a :: k) # | |
Defined in Servant.API.Stream Methods header :: Proxy NetstringFraming -> Proxy a -> ByteString # boundary :: Proxy NetstringFraming -> Proxy a -> BoundaryStrategy # trailer :: Proxy NetstringFraming -> Proxy a -> ByteString # | |