API Reference

Class List

pc.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.

get

Perform an HTTP GET request to the given url.

get

Perform an HTTP GET request to the given url.

post

Perform an HTTP POST request to the given url.

post

Perform an HTTP POST request to the given url.

put

Perform an HTTP PUT request to the given url.

put

Perform an HTTP PUT request to the given url.

request

Make a general purpose HTTP request.

request

Make a general purpose HTTP request.

Details

Constructor

Http()

Create a new Http instance. By default, a PlayCanvas application creates an instance of this object at pc.http.

Methods

del(url, callback)

Perform an HTTP DELETE request to the given url.

Parameters

urlobject

The URL to make the request to.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

del(url, options, callback)

Perform an HTTP DELETE request to the given url.

Parameters

urlobject

The URL to make the request to.

optionsobject

Additional options.

options.headersobject

HTTP headers to add to the request.

options.asyncboolean

Make the request asynchronously. Defaults to true.

options.cacheobject

If false, then add a timestamp to the request to prevent caching.

options.withCredentialsboolean

Send cookies with this request. Defaults to false.

options.responseTypestring

Override the response type.

options.postdataDocument, 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.retryboolean

If true then if the request fails it will be retried with an exponential backoff.

options.maxRetriesnumber

If options.retry is true this specifies the maximum number of retries. Defaults to 5.

options.maxRetryDelaynumber

If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The 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

urlstring

The URL to make the request to.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

get(url, options, callback)

Perform an HTTP GET request to the given url.

Parameters

urlstring

The URL to make the request to.

optionsobject

Additional options.

options.headersobject

HTTP headers to add to the request.

options.asyncboolean

Make the request asynchronously. Defaults to true.

options.cacheobject

If false, then add a timestamp to the request to prevent caching.

options.withCredentialsboolean

Send cookies with this request. Defaults to false.

options.responseTypestring

Override the response type.

options.postdataDocument, 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.retryboolean

If true then if the request fails it will be retried with an exponential backoff.

options.maxRetriesnumber

If options.retry is true this specifies the maximum number of retries. Defaults to 5.

options.maxRetryDelaynumber

If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

post(url, data, callback)

Perform an HTTP POST request to the given url.

Parameters

urlstring

The URL to make the request to.

dataobject

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.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

post(url, data, options, callback)

Perform an HTTP POST request to the given url.

Parameters

urlstring

The URL to make the request to.

dataobject

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.

optionsobject

Additional options.

options.headersobject

HTTP headers to add to the request.

options.asyncboolean

Make the request asynchronously. Defaults to true.

options.cacheobject

If false, then add a timestamp to the request to prevent caching.

options.withCredentialsboolean

Send cookies with this request. Defaults to false.

options.responseTypestring

Override the response type.

options.retryboolean

If true then if the request fails it will be retried with an exponential backoff.

options.maxRetriesnumber

If options.retry is true this specifies the maximum number of retries. Defaults to 5.

options.maxRetryDelaynumber

If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

put(url, data, callback)

Perform an HTTP PUT request to the given url.

Parameters

urlstring

The URL to make the request to.

dataDocument, 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.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

put(url, data, options, callback)

Perform an HTTP PUT request to the given url.

Parameters

urlstring

The URL to make the request to.

dataDocument, 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.

optionsobject

Additional options.

options.headersobject

HTTP headers to add to the request.

options.asyncboolean

Make the request asynchronously. Defaults to true.

options.cacheobject

If false, then add a timestamp to the request to prevent caching.

options.withCredentialsboolean

Send cookies with this request. Defaults to false.

options.responseTypestring

Override the response type.

options.retryboolean

If true then if the request fails it will be retried with an exponential backoff.

options.maxRetriesnumber

If options.retry is true this specifies the maximum number of retries. Defaults to 5.

options.maxRetryDelaynumber

If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

request(method, url, callback)

Make a general purpose HTTP request.

Parameters

methodstring

The HTTP method "GET", "POST", "PUT", "DELETE".

urlstring

The url to make the request to.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.

request(method, url, options, callback)

Make a general purpose HTTP request.

Parameters

methodstring

The HTTP method "GET", "POST", "PUT", "DELETE".

urlstring

The url to make the request to.

optionsobject

Additional options.

options.headersobject

HTTP headers to add to the request.

options.asyncboolean

Make the request asynchronously. Defaults to true.

options.cacheobject

If false, then add a timestamp to the request to prevent caching.

options.withCredentialsboolean

Send cookies with this request. Defaults to false.

options.retryboolean

If true then if the request fails it will be retried with an exponential backoff.

options.maxRetriesnumber

If options.retry is true this specifies the maximum number of retries. Defaults to 5.

options.maxRetryDelaynumber

If options.retry is true this specifies the maximum amount of time to wait between retries in milliseconds. Defaults to 5000.

options.responseTypestring

Override the response type.

options.postdataDocument, 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.

callbackpc.callbacks.HttpResponse

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

XMLHttpRequest

The request object.