Prettynice.Response

HTTP Responses

type alias Response msg = Response msg

An HTTP response value.

Setting the Response Body

asHtml :
{ title : String
, head : Array (Html msg)
, body : Array (Html msg)
}
-> Response msg
-> Response msg

Update a response to send HTML.

title will go into the <title> tag, head will be added to the <head> tag, and body will go into the <body> tag.

Note that Prettynice uses and expects Html from icidasset/html-gren, not from gren-lang/browser. The API is the same, but html-gren is needed because it supports server-side rendering.

See the html example for a working usage example.

asJson : Value -> Response msg -> Response msg

Update a response to send json.

See the json example for a working usage example.

asText : String -> Response msg -> Response msg

Update a response to send plain text.

See the hello world example for a working usage example.

asBytes :
{ contentType : String
, body : Bytes
}
-> Response msg
-> Response msg

Update a response to send raw bytes.

Use this to send binary data like files, images, etc. See the bytes example for a working usage example.

Setting the Response headers and status

setHeader : String -> String -> Response msg -> Response msg

Add a header to the response.

setStatus : Int -> Response msg -> Response msg

Set the status of the response.

Event Messages

onSend : msg -> Response msg -> Response msg

Send a message to your update function when a response is sent.

See the websocket example for a working usage example.

Raw HTTP Responses

Use these functions to work with a raw Http.Response directly. You shouldn't need them in a typical Prettynice application but if you want to do something weird and cool I'm not going to stop you.

new : Response -> Response msg

Turn a Node HttpServer Response into a Prettynice Response.

You shouldn't need this in your normal application code. The response you get in a Prettynice request message is already a Prettynice Response.

unwrap : Response msg -> Response

Turn a Prettynice Response back into a normal Node HttpServer Response

You shouldn't need this in a typical Prettynice program. But it's here if you want to do anything weird and cool.