| License | MIT |
|---|---|
| Maintainer | Yogesh Sajanikar <yogesh_sajanikar@yahoo.com> |
| Stability | experimental |
| Portability | POSIX, WINDOWS |
| Safe Haskell | None |
| Language | Haskell2010 |
Thrift.Transport.Wai
Description
Support thrift transport for Wai Request and Response.
- data RequestTransport
- fromRequest :: Request -> IO RequestTransport
- data StreamTransport
- toStreamTransport :: (Builder -> IO ()) -> IO () -> StreamTransport
- thriftStreamingBody :: (Protocol ip, Protocol op) => h -> (RequestTransport -> ip RequestTransport) -> (StreamTransport -> op StreamTransport) -> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool) -> Request -> StreamingBody
- thriftApp :: (Protocol ip, Protocol op) => h -> (RequestTransport -> ip RequestTransport) -> (StreamTransport -> op StreamTransport) -> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool) -> Application
- thriftMiddleware :: (Protocol ip, Protocol op) => h -> (RequestTransport -> ip RequestTransport) -> (StreamTransport -> op StreamTransport) -> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool) -> Middleware
Request Transport
data RequestTransport Source
Transport layer based on Request
This is a readonly transport layer. Write operations will fail.
Instances
fromRequest :: Request -> IO RequestTransport Source
Creates RequestTransport from WAI request Initilizes RequestTransport with a lazy request body from request
Stream Transport for response
data StreamTransport Source
StreamTransport is write-only transport layer for thrift Transport
Instances
Arguments
| :: (Builder -> IO ()) | Builder for building the chunks |
| -> IO () | Flush the content to the response stream |
| -> StreamTransport |
|
Create StreamTransport from two parts, builder creating the chunk
and flush, to flush the chunk to response stream. This is very similar
to StreamingBody
Wai compatible application and middleware
Arguments
| :: (Protocol ip, Protocol op) | |
| => h | Type supporting thrift generated interface |
| -> (RequestTransport -> ip RequestTransport) | Input protocol selector for |
| -> (StreamTransport -> op StreamTransport) | Output protocol selector for |
| -> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool) | Thrift request handler |
| -> Request | Wai request, to be embedded in |
| -> StreamingBody | Wai |
Creates a streaming body that processes the request, and responds by
calling thrift handler. It uses RequestTransport for processing the thrift
input, and StreamTransport for responding through StreamingBody
This is a very useful function, and is in fact used implement thriftWaiApp
and thriftMiddleware
For example one can use thriftStreamingBody with scotty as
import qualified Greeting as G -- Thrift generated code
thriftStream :: ActionM ()
thriftStream = do
req <- request
stream $ thriftStreamingBody G.GreetData JSONProtocol JSONProtocol G.process
Arguments
| :: (Protocol ip, Protocol op) | |
| => h | Type supporting thrift generated interface |
| -> (RequestTransport -> ip RequestTransport) | Input protocol selector for |
| -> (StreamTransport -> op StreamTransport) | Output protocol selector for |
| -> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool) | Thrift request handler |
| -> Application | Wai application |
Wai compatible application. This does not add the necessary headers. This does not add necessary headers for allowing cross origin requests
Arguments
| :: (Protocol ip, Protocol op) | |
| => h | Type supporting thrift generated interface |
| -> (RequestTransport -> ip RequestTransport) | Input protocol selector for |
| -> (StreamTransport -> op StreamTransport) | Output protocol selector for |
| -> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool) | Thrift request handler |
| -> Middleware | Wai middleware |
Creates Wai middleware for the given handler This does not add necessary headers for allowing cross origin requests