Prettynice
Use this module to define and start a Prettynice web server.
The definition of your Prettynice program.
Defining your program
Define a Prettynice web server.
Servers are defined with two functions: init
is used to start your program
and router
will be called on every request and should return a task that resolves to a response.
See server/src/Main.gren
in the example projects for how to use this in practice.
Starting your pgoram
Init task for starting your Prettynice program.
Created with startProgram
.
Start a Prettynice web server. You should call this in your init
function.
It can be wrapped in one or more calls to Init.await if you need to run a task or initialize any subsystems before starting. See the database example for an example of this.
If you are using defineFullProgram
and want to include a
command as part of your init, you can use startFullProgram
instead.
See server/src/Main.gren
in the example projects for how to use this in practice.
Messages, Commands, and Subscriptions
Sometimes init
and router
are not enough.
Maybe you need access to commands
or ports on the server side.
If so, you can use these functions to create a program that includes update
and subscriptions
.
Define a Prettynice web server that uses the full Elm Architecture.
This is the same as defineProgram
, but with the addition of
update
and subscription
functions. They work just like they do in a normal
Gren node program.
You should only need this if your server needs access to
commands
(e.g. for server-side ports)
or subscriptions.
If you don't need them, you probably want defineProgram
.
See server/src/Main.gren
in the server-side-tea example
for how defineFullProgram
is used in practice.
Start a Prettynice web server that includes an init command.
This works just like startProgram
with the addition of a command
field to send a command on init.
See server/src/Main.gren
in the bytes example
for an example usage of startFullProgram
(it reads a file on init).