Module ringo/httpclient

A scalable HTTP client that provides both synchronous and asynchronous modes of operation.

Functions

  • del (url, data, success, error)
  • get (url, data, success, error)
  • post (url, data, success, error)
  • put (url, data, success, error)
  • request (options)

Class Client

Instance Methods

  • del (url, data, success, error)
  • get (url, data, success, error)
  • post (url, data, success, error)
  • put (url, data, success, error)
  • request (options)

Client (timeout)

A HttpClient which can be used for multiple requests.

Use this Client instead of the convinience methods if you do lots of requests (especially if they go to the same hosts) or if you want cookies to be preserved between multiple requests.

Parameters

Number timeout The connection timeout

Client.prototype.del (url, data, success, error)

Make a DELETE request.

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 Type

Exchange exchange object

Client.prototype.get (url, data, success, error)

Make a GET request.

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 Type

Exchange exchange object

Client.prototype.post (url, data, success, error)

Make a POST request.

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 Type

Exchange exchange object

Client.prototype.put (url, data, success, error)

Make a PUT request.

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 Type

Exchange exchange object

Client.prototype.request (options)

Make a generic request.

Generic request options

The options object may contain the following properties:

  • url: the request URL
  • method: request method such as GET or POST
  • data: request data as string, object, or, for POST or PUT requests, Stream or Binary.
  • headers: request headers
  • username: username for HTTP authentication
  • password: password for HTTP authentication
  • contentType: the contentType
  • async: if true this method will return immedialtely , else it will block until the request is completed
  • binary: if true if content should be delivered as binary, else it will be decoded to string

Callbacks

The options object may also contain the following callback functions:

  • complete: called when the request is completed
  • success: called when the request is completed successfully
  • error: called when the request is completed with an error
  • part: called when a part of the response is available
  • beforeSend: called with the Exchange object as argument before the request is sent
The following arguments are passed to the complete, success and part callbacks:
  1. content: the content as String or ByteString
  2. status: the HTTP status code
  3. contentType: the content type
  4. exchange: the exchange object
The following arguments are passed to the error callback:
  1. message: the error message. This is either the message from an exception thrown during request processing or an HTTP error message
  2. status: the HTTP status code. This is 0 if no response was received
  3. exchange: the exchange object

Parameters

Object options

Returns Type

Exchange exchange object

del (url, data, success, error)

Convenience function to make a DELETE request without creating a new client.

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 Type

Exchange exchange object

get (url, data, success, error)

Convenience function to make a GET request without creating a new client.

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 Type

Exchange exchange object

post (url, data, success, error)

Convenience function to make a POST request without creating a new client.

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 Type

Exchange exchange object

put (url, data, success, error)

Convenience function to make a PUT request without creating a new client.

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 Type

Exchange exchange object

request (options)

Convenience function to make a generic HTTP request without creating a new client.

Parameters

Object options

Returns Type

Exchange exchange object