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)
Instance Methods
-
del(url, data, success, error)
-
get(url, data, success, error)
-
post(url, data, success, error)
-
put(url, data, success, error)
-
request(options)
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)
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 |
See
Client.prototype.get
(url, data, success, error)
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 |
See
Client.prototype.post
(url, data, success, error)
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 |
See
Client.prototype.put
(url, data, success, error)
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 |
See
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:
content: the content as String or ByteString
status: the HTTP status code
contentType: the content type
exchange: the exchange object
The following arguments are passed to the
error callback:
message: the error message. This is either the message from an exception thrown
during request processing or an HTTP error message
status: the HTTP status code. This is 0 if no response was received
exchange: the 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 |
See
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 |
See
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 |
See
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 |
See
Convenience function to make a generic HTTP request without creating a new client.
See