Module ringo/httpclient
A scalable HTTP client that provides both synchronous and asynchronous modes of operation.
Exchange ()
An Exchange encapsulates the Request and Response of an HTTP Exchange.
Exchange.prototype.content
The response body as String
Exchange.prototype.contentBytes
The response body as ByteString
Exchange.prototype.contentChunk
Exchange.prototype.contentExchange
The Jetty ContentExchange object
Exchange.prototype.contentType
The response content type
Exchange.prototype.cookies
The cookies set by the server
Exchange.prototype.done
True if the request has completed, false otherwise
Exchange.prototype.encoding
The response encoding
Exchange.prototype.headers
The response headers
Exchange.prototype.status
The response status code
Exchange.prototype.wait ()
Waits for the request to complete and returns the Exchange object itself. This method returns immediately if the request has already completed. Otherwise, it will block the current thread until completion.
Returns
| the Exchange object |
del (url, data, success, error)
Make a DELETE request. If a success callback is provided, the request is executed asynchronously and the function returns immediately. Otherwise, the function blocks until the request terminates.
Parameters
| String | url | the url to request |
| Object|String | data | request data, optional |
| Function | success | callback in case of successful status code, optional |
| Function | error | callback in case of any error - transmission or response, optional |
Returns
| Exchange | exchange object |
See
get (url, data, success, error)
Make a GET request. If a success callback is provided, the request is executed asynchronously and the function returns immediately. Otherwise, the function blocks until the request terminates.
Parameters
| String | url | the url to request |
| Object|String | data | request data, optional |
| Function | success | callback in case of successful status code, optional |
| Function | error | callback in case of any error - transmission or response, optional |
Returns
| Exchange | exchange object |
See
post (url, data, success, error)
Make a POST request. If a success callback is provided, the request is executed asynchronously and the function returns immediately. Otherwise, the function blocks until the request terminates.
Parameters
| String | url | the url to request |
| Object|String|Binary|Stream | data | request data, optional |
| Function | success | callback in case of successful status code, optional |
| Function | error | callback in case of any error - transmission or response, optional |
Returns
| Exchange | exchange object |
See
put (url, data, success, error)
Make a PUT request. If a success callback is provided, the request is executed asynchronously and the function returns immediately. Otherwise, the function blocks until the request terminates.
Parameters
| String | url | the url to request |
| Object|String|Binary|Stream | data | request data, optional |
| Function | success | callback in case of successful status code, optional |
| Function | error | callback in case of any error - transmission or response, optional |
Returns
| Exchange | exchange object |
See
request (options)
Make a generic request.
Generic request options
The options object may contain the following properties:
url: the request URLmethod: request method such as GET or POSTdata: request data as string, object, or, for POST or PUT requests, Stream or Binary.headers: request headersusername: username for HTTP authenticationpassword: password for HTTP authenticationcontentType: the contentTypeasync: if true this method will return immedialtely , else it will block until the request is completedbinary: if true if content should be delivered as binary, else it will be decoded to stringpromise: if true a promise that resolves to the request's Exchange object is returned instead of the Exchange object itself
Callbacks
The options object may also contain the following callback functions:
complete: called when the request is completedsuccess: called when the request is completed successfullyerror: called when the request is completed with an errorpart: called when a part of the response is availablebeforeSend: called with the Exchange object as argument before the request is sent
complete, success and part callbacks:
content: the content as String or ByteStringstatus: the HTTP status codecontentType: the content typeexchange: the exchange object
error callback:
message: the error message. This is either the message from an exception thrown during request processing or an HTTP error messagestatus: the HTTP status code. This is0if no response was receivedexchange: the exchange object
Parameters
| Object | options |
Returns
| Exchange | exchange object |
