Http
Used to send and receive HTTP requests.
Summary
Methods
del | Perform an HTTP DELETE request to the given url. |
del | Perform an HTTP DELETE request to the given url with additional options such as headers, retries, credentials, etc. |
get | Perform an HTTP GET request to the given url. |
get | Perform an HTTP GET request to the given url with additional options such as headers, retries, credentials, etc. |
post | Perform an HTTP POST request to the given url. |
post | Perform an HTTP POST request to the given url with additional options such as headers, retries, credentials, etc. |
put | Perform an HTTP PUT request to the given url. |
put | Perform an HTTP PUT request to the given url with additional options such as headers, retries, credentials, etc. |
request | Make a general purpose HTTP request. |
request | Make a general purpose HTTP request with additional options such as headers, retries, credentials, etc. |
Details
Constructor
Http()
Methods
del(url, callback)
Perform an HTTP DELETE request to the given url.
pc.http.del("http://example.com/", function (err, response) {
console.log(response);
});
Parameters
url | object | The URL to make the request to. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
del(url, options, callback)
Perform an HTTP DELETE request to the given url with additional options such as headers, retries, credentials, etc.
pc.http.del("http://example.com/", { "retry": true, "maxRetries": 5 }, function (err, response) {
console.log(response);
});
Parameters
url | object | The URL to make the request to. |
options | object | Additional options. |
options.headers | object | HTTP headers to add to the request. |
options.async | boolean | Make the request asynchronously. Defaults to true. |
options.cache | boolean | If false, then add a timestamp to the request to prevent caching. |
options.withCredentials | boolean | Send cookies with this request. Defaults to false. |
options.responseType | string | Override the response type. |
options.postdata | Document, object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
options.retry | boolean | If true then if the request fails it will be retried with an exponential backoff. |
options.maxRetries | number | If options.retry is true this specifies the maximum number of retries. Defaults to 5. |
options.maxRetryDelay | number | If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
get(url, callback)
Perform an HTTP GET request to the given url.
pc.http.get("http://example.com/", function (err, response) {
console.log(response);
});
Parameters
url | string | The URL to make the request to. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
get(url, options, callback)
Perform an HTTP GET request to the given url with additional options such as headers, retries, credentials, etc.
pc.http.get("http://example.com/", { "retry": true, "maxRetries": 5 }, function (err, response) {
console.log(response);
});
Parameters
url | string | The URL to make the request to. |
options | object | Additional options. |
options.headers | object | HTTP headers to add to the request. |
options.async | boolean | Make the request asynchronously. Defaults to true. |
options.cache | boolean | If false, then add a timestamp to the request to prevent caching. |
options.withCredentials | boolean | Send cookies with this request. Defaults to false. |
options.responseType | string | Override the response type. |
options.postdata | Document, object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
options.retry | boolean | If true then if the request fails it will be retried with an exponential backoff. |
options.maxRetries | number | If options.retry is true this specifies the maximum number of retries. Defaults to 5. |
options.maxRetryDelay | number | If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
post(url, data, callback)
Perform an HTTP POST request to the given url.
pc.http.post("http://example.com/", { "name": "Alix" }, function (err, response) {
console.log(response);
});
Parameters
url | string | The URL to make the request to. |
data | object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
post(url, data, options, callback)
Perform an HTTP POST request to the given url with additional options such as headers, retries, credentials, etc.
pc.http.post("http://example.com/", { "name": "Alix" }, { "retry": true, "maxRetries": 5 }, function (err, response) {
console.log(response);
});
Parameters
url | string | The URL to make the request to. |
data | object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
options | object | Additional options. |
options.headers | object | HTTP headers to add to the request. |
options.async | boolean | Make the request asynchronously. Defaults to true. |
options.cache | boolean | If false, then add a timestamp to the request to prevent caching. |
options.withCredentials | boolean | Send cookies with this request. Defaults to false. |
options.responseType | string | Override the response type. |
options.retry | boolean | If true then if the request fails it will be retried with an exponential backoff. |
options.maxRetries | number | If options.retry is true this specifies the maximum number of retries. Defaults to 5. |
options.maxRetryDelay | number | If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
put(url, data, callback)
Perform an HTTP PUT request to the given url.
pc.http.put("http://example.com/", { "name": "Alix" }, function (err, response) {
console.log(response);
});
Parameters
url | string | The URL to make the request to. |
data | Document, object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
put(url, data, options, callback)
Perform an HTTP PUT request to the given url with additional options such as headers, retries, credentials, etc.
pc.http.put("http://example.com/", { "name": "Alix" }, { "retry": true, "maxRetries": 5 }, function (err, response) {
console.log(response);
});
Parameters
url | string | The URL to make the request to. |
data | Document, object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
options | object | Additional options. |
options.headers | object | HTTP headers to add to the request. |
options.async | boolean | Make the request asynchronously. Defaults to true. |
options.cache | boolean | If false, then add a timestamp to the request to prevent caching. |
options.withCredentials | boolean | Send cookies with this request. Defaults to false. |
options.responseType | string | Override the response type. |
options.retry | boolean | If true then if the request fails it will be retried with an exponential backoff. |
options.maxRetries | number | If options.retry is true this specifies the maximum number of retries. Defaults to 5. |
options.maxRetryDelay | number | If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
request(method, url, callback)
Make a general purpose HTTP request.
pc.http.request("get", "http://example.com/", function (err, response) {
console.log(response);
});
Parameters
method | string | The HTTP method "GET", "POST", "PUT", "DELETE". |
url | string | The url to make the request to. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.
request(method, url, options, callback)
Make a general purpose HTTP request with additional options such as headers, retries, credentials, etc.
pc.http.request("get", "http://example.com/", { "retry": true, "maxRetries": 5 }, function (err, response) {
console.log(response);
});
Parameters
method | string | The HTTP method "GET", "POST", "PUT", "DELETE". |
url | string | The url to make the request to. |
options | object | Additional options. |
options.headers | object | HTTP headers to add to the request. |
options.async | boolean | Make the request asynchronously. Defaults to true. |
options.cache | boolean | If false, then add a timestamp to the request to prevent caching. |
options.withCredentials | boolean | Send cookies with this request. Defaults to false. |
options.retry | boolean | If true then if the request fails it will be retried with an exponential backoff. |
options.maxRetries | number | If options.retry is true this specifies the maximum number of retries. Defaults to 5. |
options.maxRetryDelay | number | If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000. |
options.responseType | string | Override the response type. |
options.postdata | Document, object | Data to send in the body of the request. Some content types are handled automatically. If postdata is an XML Document, it is handled. If the Content-Type header is set to 'application/json' then the postdata is JSON stringified. Otherwise, by default, the data is sent as form-urlencoded. |
callback | HttpResponseCallback | The callback used when the response has returned. Passed (err, data) where data is the response (format depends on response type: text, Object, ArrayBuffer, XML) and err is the error code. |
Returns
XMLHttpRequestThe request object.