beakr (version 0.3.1)

listen: Listen for connections on a Beakr instance

Description

Binds and listens for connections at the specified host and port.

Usage

listen(
  beakr = NULL,
  host = "127.0.0.1",
  port = 25118,
  daemon = FALSE,
  verbose = TRUE
)

Arguments

beakr

Beakr instance.

host

String that is a valid IPv4 or IPv6 address to listen on. Defaults to the local host ("127.0.0.1").

port

Number or integer that indicates the port to listen on. Default is a port opened on 25118.

daemon

Logical specifying whether the server should be run in the background.

verbose

Logical specifying whether to print out details of the Beakr instance now running.

Value

A Beakr instance with an active server.

Details

listen() binds the specified host and port and listens for connections on a thread. The thread handles incoming requests. when it receives an HTTP request, it will schedule a call to the user-defined middleware and handle the request.

If daemon = TRUE, listen() binds the specified port and listens for connections on a thread running in the background.

See the httpuv package for more details.

Examples

Run this code
# NOT RUN {
# Run in the background
beakr <- newBeakr()
beakr %>%
  httpGET("/", function(req, res, err) {
    return("Successful GET request!\n")
  }) %>%
  listen(daemon = TRUE)

# Stop the server
stopServer(beakr)
# }

Run the code above in your browser using DataLab