This library provides a common interface for communication between web applications and web servers.
WAI cannot be used standalone, it requires a server handler such as warp.
This library is not yet published to pursuit.
You can install this package by adding the details below to your packages.dhall:
let additions =
{ wai =
{ dependencies = [ "aff", "effect", "http-types", "node-net" ]
, repo =
"https://github.com/Woody88/purescript-wai.git"
, version =
"master"
}
, http-types =
{ dependencies = [ "tuples", "unicode", "generics-rep" ]
, repo =
"https://github.com/Woody88/purescript-http-types.git"
, version =
"master"
}
}
user@user:~$ spago install wai
WAI models applications using a request-response flow.
type Application = Request -> (Response -> Aff ResponseReceived) -> Aff ResponseReceived
An application is a function that receives a request along with a continuation function for sending the response.
Middleware is an application transformer. That is, a function from application to application:
type Middleware = Application -> Application
Because these are simply functions, they can be composed in any order.
middlewares :: Middleware
middlewares = myCustomMiddleware1 >>> myCustomMiddleware2
myCustomMiddleware1 :: Middleware
myCustomMiddleware1 app req send = ...
myCustomMiddleware2 :: Middleware
myCustomMiddleware2 app req send = ...
This enables us to write declarative, composable middleware:
requireAuthToken :: Middleware
requireAuthToken app req send
| hasAuthToken req = app req send
| otherwise = send $ responseStr unauthorized401 [] "Missing Token!"
where
hasAuthToken :: Request -> Boolean
hasAuthToken req = ...
-- Creates a `Response` from a string. This helper function is provided by WAI.
responseStr :: Status -> ResponseHeaders -> String -> Response
If you are interested in fixing issues and contributing directly to the code base, please see the contributing guidelines.
Change log details can be found here
Licensed under the MIT license. Copyright (c) 2021 Woodson Delhia. All rights reserved.