4 ms·
A WAI `Application` is defined as the following type alias: type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceive
by jkachmar 6y ago
A WAI `Application` is defined as the following type alias:
type Application =
Request ->
(Response -> IO ResponseReceived) ->
IO ResponseReceived
...which is to say that WAI applications are “just” functions that accept an incoming request and a callback that turns that request into a response object (which may emit side effects), and which return a respond object (which may emit side effects).
This leads to a very nice definition for middleware as the following type alias:
type Middleware =
Application ->
Application
...which says that any WAI middleware is just a function that turns one application into another.
This means that WAI applications have a nice and easy to understand top-level interface, and that complex chains of WAI middleware can be built up by chaining smaller middlewares together.
The potential benefit here (over other language frameworks) is that the “grammar” being used to describe applications and middleware is the same “grammar” that’s used in most other Haskell applications
(i.e. function composition). Ideally, this should make it more easily understandable to a Haskell practitioner who might not be intimately familiar with the framework at first glance.
- acidbaseextract 6y agoNot to be trite, but uh... like WSGI or Rack?
- agentultra 6y agoI think the specifications are functionally equivalent and differ only in their approach. I think WAI is influenced directly by WSGI/RACK.