Prettynice

Use this module to define your server as a full-fledged program that can send commands, respond to messages, and listen for subscriptions, just like a normal Node program.

Note: If all you want to do is respond to requests with simple responses, look at Prettynice.SimpleRouter instead.

Typically you will use defineProgram in your main, and startProgram in your init. See below for details. Or check out some complete example programs that use this module:

Defining your program

defineProgram :
{ init : Environment -> Init appModel appMsg
, update : AppUpdate appModel appMsg
, subscriptions : appModel -> Sub appMsg
, onRequest : Request -> Response -> appMsg
}
-> Program appModel appMsg

Define your Prettynice program.

This will give you a Program that you can return from your main function.

If you don't need the full model/update/view cycle, see Prettynice.SimpleRouter instead.

type alias Program appModel appMsg = Program (Model appModel) (Msg appModel appMsg)

The definition of your Prettynice program.

Starting your program

startProgram : Config appModel appMsg -> Init appModel appMsg

Start your server!

This creates the startup task you can return from your init function.

type alias Config appModel appMsg =
{ host : String
, port_ : Int
, env : Environment
, model : appModel
, command : Cmd appMsg
}

Application config. You will pass this to startProgram.

type alias Init appModel appMsg =
Task { model : Model appModel
, command : Cmd (Msg appModel appMsg)
}

The task that starts your program. It should be returned from your init function.

You will get this from startProgram, which you can wrap in an await if you need to initialize other subsystems (see the running-tasks example for an example of this).