wireform-http-wai
wireform-http-wai is a bidirectional adapter between WAI (the Web
Application Interface) and the wireform-http unified
request/response types. Use it to exercise existing WAI applications with
wireform-http client tooling, or to serve wireform-http handlers through
Warp or any WAI-compatible server.
The package exposes a single module, Network.HTTP.WAI, which carries the
conversion functions in both directions plus the higher-level adapters.
Key features
Section titled “Key features”- Run WAI apps as a wireform-http
HandlerwithwaiToHandler - Drive WAI apps through a wireform-http
Transportfor in-process client testing with the full middleware stack (waiTransport) - Serve wireform-http handlers through Warp (or any WAI server) with
handlerToWai - Low-level conversions for method, status, version, headers, request,
and response (
toWai*/fromWai*)
Basic usage
Section titled “Basic usage”Wrap an existing WAI Application so wireform-http can call it:
import qualified Network.Wai as Waiimport Network.HTTP.WAI (waiToHandler, waiTransport)
myWaiApp :: Wai.ApplicationmyWaiApp = ...
-- Use as a wireform-http Handler (server-level types)handler :: Network.HTTP.Server.Handlerhandler = waiToHandler myWaiApp
-- Or as a wireform-http client Transport for in-process testingtransport :: Network.HTTP.Client.Transport.Transport IOtransport = waiTransport myWaiAppServe a wireform-http handler through Warp:
import qualified Network.Wai.Handler.Warp as Warpimport Network.HTTP.WAI (handlerToWai)
myHandler :: Network.HTTP.Server.HandlermyHandler req = ...
main :: IO ()main = Warp.run 8080 (handlerToWai myHandler)Notable functions
Section titled “Notable functions”All exported from the single module Network.HTTP.WAI:
| Function | Purpose |
|---|---|
waiToHandler | Run a WAI Application as a wireform-http Handler |
handlerToWai | Expose a wireform-http handler as a WAI Application |
waiTransport | Drive a WAI Application through a client-level Transport |
toWaiRequest / fromWaiRequest | Request conversion in both directions |
toWaiResponse / fromWaiResponse | Response conversion in both directions |
toWaiMethod / fromWaiMethod | Method conversion |
toWaiStatus / fromWaiStatus | Status conversion |
toWaiHeaders / fromWaiHeaders | Header conversion |
Limitations
Section titled “Limitations”- WAI
responseRaw(WebSocket upgrade) is not supported; the adapter converts the backup response. Use a real TCP server for upgrade testing. fromWaiResponsematerialises the entire response body into memory. For large streaming responses, test at the WAI level directly.