Module ringo/httpclient
A scalable HTTP client that provides both synchronous and asynchronous modes of operation.
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 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 string
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 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 |