Prettynice.SimpleRouter

An HTTP server program that routes requests to simple responses.

A router is a function that takes a Request and a Response and returns a command to send the response.

Typically you will use defineProgram in your main, and startProgram in your init. See below for details.

See examples/routing for a full working example.

Note: If you need more control over your program (e.g. you need ports, or want to run a task before responding) you will want to use the Prettynice module instead.

Defining your router

defineProgram :
{ init : Environment -> Init
, router : Request -> Response -> Cmd Msg
}
-> Program

Define your router program.

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

If you need a full model/update/view cycle, see the Prettynice module instead.

type alias Program = Program Model Msg

The definition of your router program.

Starting your router

startProgram : Config -> Init

Start your router program!

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

type alias Config = { host : String, port_ : Int, env : Environment }

Application config. You will pass this to startProgram.

type alias Init = Task { model : Model, command : Cmd Msg }

The task that starts your router 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).