HTTP Responses

type Response

An HTTP response value.

type Body msg
= HtmlBody ({ title : String, head : Array (Html msg), body : Array (Html msg) })
| JsonBody Value
| TextBody String

Custom type for text-based response bodies.

new : Response -> Response

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.

Updating Responses

setStatus : Int -> Response -> Response

Set the status of the response.

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

Add a header to the response.

setBody : Body msg -> Response -> Response

Set the body of the response directly.

Normally you can use one of the send* functions, but if you need more control, you can set a Body directly.

Sending Responses

You can construct and send a Response directly with send, or you can use one of the send* helpers to send data with the content-type set automatically.

send : Response -> Cmd a

Command to send a response to the current HTTP request.

sendHtml :
{ title : String
, head : Array (Html msg)
, body : Array (Html msg)
-> Response
-> Cmd msg

Respond with 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.

sendText : String -> Response -> Cmd a

Respond with plain text.

sendJson : Value -> Response -> Cmd a

Respond with Json.

sendBytes : { contentType : String, body : Bytes } -> Response -> Cmd a

Respond with raw bytes.

Use this to send binary data like files, images, etc.