http-messages {tryr}R Documentation

Generic HTTP Response Messages

Description

These functions provide generic HTTP response messages based on the HTTP response status codes.

Usage

http_error(status = 500L, message = NULL)

http_success(status = 200L, message = NULL, body = NULL)

http_response(status = 200L, message = NULL, body = NULL)

http_handler(req, res, status = 200L, message = NULL, body = NULL)

Arguments

status

HTTP status code.

message

An HTTP response message or NULL. A generic response message is provided when it is NULL based on http_status_codes.

body

A list, additional values to be returned.

req

The request object.

res

The response object.

Value

http_error returns an error with a custom condition attribute after checking if the status code is at least 400.

http_success returns a list but checks that the status code is <400.

http_response returns a list checking only that the status code is valid.

http_handler behaves like http_response but it also sets the status code and the body of the response object.

See Also

http_status_codes

Examples

try(http_error())
try(http_error(400))
try(http_error(400, "Sorry"))

str(http_success())
str(http_success(201))
str(http_success(201, "Awesome"))

str(http_response(201, "Awesome", list(name = "Jane", count = 6)))

req <- new.env()
res <- new.env()
str(http_handler(req, res, 201, "Awesome", list(name = "Jane", count = 6)))
res$status
str(res$body)



[Package tryr version 0.1.1 Index]