Used to send and receive HTTP requests.

Methods

  • Perform an HTTP DELETE request to the given url with additional options such as headers, retries, credentials, etc.

    Parameters

    • url: string

      The URL to make the request to.

    • options: {
          async?: boolean;
          cache?: boolean;
          headers?: {};
          maxRetries?: number;
          maxRetryDelay?: number;
          postdata?: object | Document;
          responseType?: string;
          retry?: boolean;
          withCredentials?: boolean;
      }

      Additional options.

      • Optionalasync?: boolean

        Make the request asynchronously. Defaults to true.

      • Optionalcache?: boolean

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

      • Optionalheaders?: {}

        HTTP headers to add to the request.

      • OptionalmaxRetries?: number

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

      • OptionalmaxRetryDelay?: number

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

      • Optionalpostdata?: object | Document

        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.

      • OptionalresponseType?: string

        Override the response type.

      • Optionalretry?: boolean

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

      • OptionalwithCredentials?: boolean

        Send cookies with this request. Defaults to false.

    • 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 XMLHttpRequest

    The request object.

    pc.http.del("http://example.com/", {
    "retry": true,
    "maxRetries": 5
    }, (err, response) => {
    console.log(response);
    });
  • Perform an HTTP GET request to the given url with additional options such as headers, retries, credentials, etc.

    Parameters

    • url: string

      The URL to make the request to.

    • options: {
          async?: boolean;
          cache?: boolean;
          headers?: {};
          maxRetries?: number;
          maxRetryDelay?: number;
          postdata?: object | Document;
          responseType?: string;
          retry?: boolean;
          withCredentials?: boolean;
      }

      Additional options.

      • Optionalasync?: boolean

        Make the request asynchronously. Defaults to true.

      • Optionalcache?: boolean

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

      • Optionalheaders?: {}

        HTTP headers to add to the request.

      • OptionalmaxRetries?: number

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

      • OptionalmaxRetryDelay?: number

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

      • Optionalpostdata?: object | Document

        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.

      • OptionalresponseType?: string

        Override the response type.

      • Optionalretry?: boolean

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

      • OptionalwithCredentials?: boolean

        Send cookies with this request. Defaults to false.

    • 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 XMLHttpRequest

    The request object.

    pc.http.get("http://example.com/", {
    "retry": true,
    "maxRetries": 5
    }, (err, response) => {
    console.log(response);
    });
  • Perform an HTTP POST request to the given url with additional options such as headers, retries, credentials, etc.

    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: {
          async?: boolean;
          cache?: boolean;
          headers?: {};
          maxRetries?: number;
          maxRetryDelay?: number;
          responseType?: string;
          retry?: boolean;
          withCredentials?: boolean;
      }

      Additional options.

      • Optionalasync?: boolean

        Make the request asynchronously. Defaults to true.

      • Optionalcache?: boolean

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

      • Optionalheaders?: {}

        HTTP headers to add to the request.

      • OptionalmaxRetries?: number

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

      • OptionalmaxRetryDelay?: number

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

      • OptionalresponseType?: string

        Override the response type.

      • Optionalretry?: boolean

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

      • OptionalwithCredentials?: boolean

        Send cookies with this request. Defaults to false.

    • 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 XMLHttpRequest

    The request object.

    pc.http.post("http://example.com/", {
    "name": "Alex"
    }, {
    "retry": true,
    "maxRetries": 5
    }, (err, response) => {
    console.log(response);
    });
  • Perform an HTTP PUT request to the given url with additional options such as headers, retries, credentials, etc.

    Parameters

    • url: string

      The URL to make the request to.

    • data: object | Document

      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: {
          async?: boolean;
          cache?: boolean;
          headers?: {};
          maxRetries?: number;
          maxRetryDelay?: number;
          responseType?: string;
          retry?: boolean;
          withCredentials?: boolean;
      }

      Additional options.

      • Optionalasync?: boolean

        Make the request asynchronously. Defaults to true.

      • Optionalcache?: boolean

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

      • Optionalheaders?: {}

        HTTP headers to add to the request.

      • OptionalmaxRetries?: number

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

      • OptionalmaxRetryDelay?: number

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

      • OptionalresponseType?: string

        Override the response type.

      • Optionalretry?: boolean

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

      • OptionalwithCredentials?: boolean

        Send cookies with this request. Defaults to false.

    • 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 XMLHttpRequest

    The request object.

    pc.http.put("http://example.com/", {
    "name": "Alex"
    }, {
    "retry": true,
    "maxRetries": 5
    }, (err, response) => {
    console.log(response);
    });
  • Make a general purpose HTTP request with additional options such as headers, retries, credentials, etc.

    Parameters

    • method: string

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

    • url: string

      The url to make the request to.

    • options: {
          async?: boolean;
          cache?: boolean;
          headers?: {};
          maxRetries?: number;
          maxRetryDelay?: number;
          postdata?: object | Document;
          responseType?: string;
          retry?: boolean;
          withCredentials?: boolean;
      }

      Additional options.

      • Optionalasync?: boolean

        Make the request asynchronously. Defaults to true.

      • Optionalcache?: boolean

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

      • Optionalheaders?: {}

        HTTP headers to add to the request.

      • OptionalmaxRetries?: number

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

      • OptionalmaxRetryDelay?: number

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

      • Optionalpostdata?: object | Document

        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.

      • OptionalresponseType?: string

        Override the response type.

      • Optionalretry?: boolean

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

      • OptionalwithCredentials?: boolean

        Send cookies with this request. Defaults to false.

    • 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 XMLHttpRequest

    The request object.

    pc.http.request("get", "http://example.com/", {
    "retry": true,
    "maxRetries": 5
    }, (err, response) => {
    console.log(response);
    });