Skip to content
mtopolnik edited this page Sep 16, 2013 · 9 revisions

A builder of HTTP requests. As documented in Global objects and functions, a ReqBuilder instance is obtained from the req global object. ReqBuilder's prototype is AsychHttpClient.BoundRequestBuilder.

(Note: an & in the method signatures marks the end of the mandatory arguments and the beginning of optional arguments.)

###get(url), put(url), post(url), delete(url), head(url), and options(url) These specify the HTTP method and URL of the request. They should be used on a named request builder; unnamed builders are obtained by calling identical methods on the req global object.

###accept(status) Sets the acceptable status code range for the response to this particular request. The API of this method is identical to the global req.acceptableStatus().

###body(b) Sets the body of the request. The argument can be:

  • a JdomBuilder: it is converted to a compact XML representation (no whitespace) and a Content-Type: text/xml;charset=UTF-8 header is added;
  • a JavaScript object or array: it is JSONized and a Content-Type: application/json;charset=UTF-8 header is added;
  • a string: it is used as-is and no content type header is added.

###delay(seconds), delay(minSeconds, maxSeconds) Causes the request to be delayed by the specified amount of seconds. If two numbers are given, a random delay is chosen within that range. Note that a call to delay() completes immediately: its effect is to delay the execution of the go() method, once it is called. Furthermore, the go() method will also complete immediately, but will schedule the execution of the request after the delay specified by `delay();

###go(& callback), goDiscardingBody(& callback) Executes the request. If a callback is specified, it will receive the response. The goDiscardingBody variant will receive the response without the body (to conserve memory). Note that the body is discarded whenever the callback is not specified, so using goDiscardingBody() with no argument is exactly the same as using go() with no argument.

Clone this wiki locally