All Projects → Woody88 → purescript-wai

Woody88 / purescript-wai

Licence: MIT license
Purescript Web Application Interface. Port of the Haskell WAI library.

Programming Languages

purescript
368 projects
Dhall
116 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to purescript-wai

wai-routes
Typesafe URLs for Haskell Wai applications
Stars: ✭ 41 (+115.79%)
Mutual labels:  wai

License CI


WAI: Web Application Interface

English   日本語   Français  

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.

Table of Contents

Installation

This library is not yet published to pursuit.
You can install this package by adding the details below to your packages.dhall:

Using Spago
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

Application

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

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

Contributing

If you are interested in fixing issues and contributing directly to the code base, please see the contributing guidelines.

Changelog

Change log details can be found here

License

Licensed under the MIT license. Copyright (c) 2021 Woodson Delhia. All rights reserved.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].