Module

Node.HTTP

This module defines low-level bindings to the Node HTTP module.

#Server

data Server

The type of a HTTP server object

#Request

data Request

A HTTP request object

#Response

data Response

A HTTP response object

#createServer

createServer :: (Request -> Response -> Effect Unit) -> Effect Server

Create a HTTP server, given a function to be executed when a request is received.

#listen

listen :: Server -> ListenOptions -> Effect Unit -> Effect Unit

Listen on a port in order to start accepting HTTP requests. The specified callback will be run when setup is complete.

#close

close :: Server -> Effect Unit -> Effect Unit

Close a listening HTTP server. The specified callback will be run the server closing is complete.

#ListenOptions

type ListenOptions = { backlog :: Maybe Int, hostname :: String, port :: Int }

Options to be supplied to listen. See the Node API for detailed information about these.

#listenSocket

listenSocket :: Server -> String -> Effect Unit -> Effect Unit

Listen on a unix socket. The specified callback will be run when setup is complete.

#onConnect

onConnect :: Server -> (Request -> Socket -> Buffer -> Effect Unit) -> Effect Unit

Listen to connect events on the server

#onUpgrade

onUpgrade :: Server -> (Request -> Socket -> Buffer -> Effect Unit) -> Effect Unit

Listen to upgrade events on the server

#httpVersion

httpVersion :: Request -> String

Get the request HTTP version

#requestHeaders

requestHeaders :: Request -> Object String

Get the request headers as a hash

#requestMethod

requestMethod :: Request -> String

Get the request method (GET, POST, etc.)

#requestURL

requestURL :: Request -> String

Get the request URL

#requestAsStream

requestAsStream :: Request -> Readable ()

Coerce the request object into a readable stream.

#setHeader

setHeader :: Response -> String -> String -> Effect Unit

Set a header with a single value.

#setHeaders

setHeaders :: Response -> String -> Array String -> Effect Unit

Set a header with multiple values.

#setStatusCode

setStatusCode :: Response -> Int -> Effect Unit

Set the status code.

#setStatusMessage

setStatusMessage :: Response -> String -> Effect Unit

Set the status message.

#responseAsStream

responseAsStream :: Response -> Writable ()

Coerce the response object into a writable stream.

Modules