MazamaWebUtils (version 0.1.7)

cgiRequest: Create a CGI Request Object

Description

A request object is created from the appropriate environment variables and is returned as a list. List elements include:

  • params -- list of request parameters

  • headers -- list of HTTP headers

  • method -- "GET"

  • raw -- NULL

  • content_type -- NULL

  • protocol -- "http"

  • body -- NULL

Usage

cgiRequest(testParams = NULL)

Arguments

testParams

URL request parameters for testing GET requests

Value

A list containing CGI request elements

Details

Even in the modern era (>= 2017) it is still sometimes useful to build simple web services using CGI scripts. Benefits include: ease of coding; use of standard port 80; service uptime: even if the CGI script dies while handling an earlier request, the script will be restarted for the next request.

Using this function, the body of an R CGI script can begin with:

req <- cgiRequest()
headers <- req$params
params <- req$params
...

References

https://github.com/Bart6114/jug/blob/master/R/request.R

Examples

Run this code
# NOT RUN {
# Example borrowed from webutils::parse_query
q <- "foo=1%2B1%3D2&bar=yin%26yang"
req <- cgiRequest(q)
str(req$params)
# }

Run the code above in your browser using DataCamp Workspace