Skip to content
Opinionated Cowboy wrapper
PureScript Makefile
Branch: master
Clone or download
Latest commit 10ea055 Jul 7, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs No warrnings Jul 6, 2019
src No warrnings Jul 6, 2019
.gitignore This is Rob's baby Feb 4, 2019
LICENSE.txt License.txt Jul 2, 2019
Makefile Add rudimentary docs Jul 6, 2019
README.md disclaimer.txt Jul 7, 2019
psc-package.json Update psc-package.json Apr 11, 2019

README.md

purescript-erl-stetson

Opinionated Bindings to Cowboy

Type-safe bindings

Direct bindings to Cowboy's API exist in the package 'erl-cowboy', but in practise this are unwieldy to build an application with - this module seeks to provide a more functional set of behaviours around the low level bindings - more sspecifically, the more REST oriented side of things.

So for example, a complete web server serving some static content would look like this

A complete web server

                      
  Stetson.configure                       -- Start configuring Stetson
    # Stetson.route "/" routeHandler      -- Define a route, invoke 'routeHandler' to find out about it
    # Stetson.port 8080                   -- Listen on port 8080
    # Stetson.bindTo 0 0 0 0              -- And all interfaces
    # Stetson.startClear "http_listener"  -- Start the listener

-- Our route handler..
routeHandler :: StetsonHandler Unit -- Has a type of 'Unit' - this is the state that gets passed around to all callbacks 
routeHandler =
  Rest.handler (\req -> Rest.initResult req unit)  -- Callback invoked on init, define the initial state (in this case, 'unit')
    # Rest.contentTypesProvided (\req state -> Rest.result (tuple2 "text/html" writeText : nil) req state) -- Callback to provide list of handlers for different content types
    # Rest.yeeha -- Finish defining the handler
  where 
    writeText req state = do -- Callback invoked when we want to serve text/html as above
      Rest.result "Hello World" req state) -- The result of providing text/html, Hello World

An actual example with more context can be found in the demo project

Disclaimer

This software, and the opinionated libraries written to support it are very much "works in progress" - we are actively using and building these libraries out for use in own commercial software and can and will be making any changes required to further support that development. As such, they come without support and a disclaimer very much of "be it on your own heads". That said - feel free to reach out and talk to us if you have ideas though, improvements and suggestions are welcome in pull requests and conversation.

You can’t perform that action at this time.