request: Create an HTTP Request

Description Usage Details Examples

Description

Request objects store relevant information sent from the client to the server as a part of an HTTP request. Request objects are not typically explicitly created. Instead, a request object is passed as an argument to a route handler.

Usage

1
2
3

Details

Request objects contain the following information.

method:

Most often GET or POST, the method indicates what action to take for a specified resource. This value may be accessed with method.

uri:

The uri indicates the server resource requested by the client. A request object's uri may be accessed with uri.

query:

A request query is set of key value pairs following the uri. A query is indicated by a ? and is, optionally, ended with a #. Query keys are case- sensitive. A request object's query list may be accessed with query. If an incoming request does not have a query string then query will return an empty list.

headers:

Request header fields may be accessed by treating a request object like a list. Using [ or [[, one can get a single or multiple header field values. Header fields are case-insensitive.

body:

The body message of a request object may be retreived with body.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# not much to see here
req <- request()
print(req)

# the request object is loaded with information
# from the client
printreq <- route(
  'GET',
  '^/print/request$',
  function(req) {
    print('Request received:')
    print(req)

    response()
  }
)

# create mockup
printreq_m <- mockup(printreq)

# now there's something to see
printreq_m('get', '/print/request')
printreq_m('get', '/print/request',
           headers = list(
             Accept = 'text/html',
             Host = 'with the most'
           )
)

nteetor/prairie documentation built on May 24, 2019, 9:56 a.m.