wai-thrift-0.0.1.3: Thrift transport layer for Wai

LicenseMIT
MaintainerYogesh Sajanikar <yogesh_sajanikar@yahoo.com>
Stabilityexperimental
PortabilityPOSIX, WINDOWS
Safe HaskellNone
LanguageHaskell2010

Thrift.Transport.Wai

Contents

Description

Support thrift transport for Wai Request and Response.

Synopsis

Request Transport

data RequestTransport Source

Transport layer based on Request This is a readonly transport layer. Write operations will fail.

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

toStreamTransport Source

Arguments

:: (Builder -> IO ())

Builder for building the chunks

-> IO ()

Flush the content to the response stream

-> StreamTransport

StreamTransport for Wai

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

thriftStreamingBody Source

Arguments

:: (Protocol ip, Protocol op) 
=> h

Type supporting thrift generated interface

-> (RequestTransport -> ip RequestTransport)

Input protocol selector for RequestTransport

-> (StreamTransport -> op StreamTransport)

Output protocol selector for StreamTransport

-> (h -> (ip RequestTransport, op StreamTransport) -> IO Bool)

Thrift request handler

-> Request

Wai request, to be embedded in RequestTransport

-> StreamingBody

Wai StreamingBody

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

thriftApp Source

Arguments

:: (Protocol ip, Protocol op) 
=> h

Type supporting thrift generated interface

-> (RequestTransport -> ip RequestTransport)

Input protocol selector for RequestTransport

-> (StreamTransport -> op StreamTransport)

Output protocol selector for StreamTransport

-> (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

thriftMiddleware Source

Arguments

:: (Protocol ip, Protocol op) 
=> h

Type supporting thrift generated interface

-> (RequestTransport -> ip RequestTransport)

Input protocol selector for RequestTransport

-> (StreamTransport -> op StreamTransport)

Output protocol selector for StreamTransport

-> (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