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/next/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
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.
The definition of your router program.
Starting your router
Start your router program!
This creates the startup task you can return from your init
function.
Application config. You will pass this to startProgram
.
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).