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.

      • async: boolean

        Make the request asynchronously. Defaults to true.

      • cache: boolean

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

      • headers: {}

        HTTP headers to add to the request.

        • maxRetries: number

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

        • maxRetryDelay: number

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

        • postdata: 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.

        • responseType: string

          Override the response type.

        • retry: boolean

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

        • withCredentials: 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.

      Example

      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.

        • async: boolean

          Make the request asynchronously. Defaults to true.

        • cache: boolean

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

        • headers: {}

          HTTP headers to add to the request.

          • maxRetries: number

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

          • maxRetryDelay: number

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

          • postdata: 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.

          • responseType: string

            Override the response type.

          • retry: boolean

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

          • withCredentials: 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.

        Example

        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.

          • async: boolean

            Make the request asynchronously. Defaults to true.

          • cache: boolean

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

          • headers: {}

            HTTP headers to add to the request.

            • maxRetries: number

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

            • maxRetryDelay: number

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

            • responseType: string

              Override the response type.

            • retry: boolean

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

            • withCredentials: 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.

          Example

          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.

            • async: boolean

              Make the request asynchronously. Defaults to true.

            • cache: boolean

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

            • headers: {}

              HTTP headers to add to the request.

              • maxRetries: number

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

              • maxRetryDelay: number

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

              • responseType: string

                Override the response type.

              • retry: boolean

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

              • withCredentials: 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.

            Example

            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.

              • async: boolean

                Make the request asynchronously. Defaults to true.

              • cache: boolean

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

              • headers: {}

                HTTP headers to add to the request.

                • maxRetries: number

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

                • maxRetryDelay: number

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

                • postdata: 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.

                • responseType: string

                  Override the response type.

                • retry: boolean

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

                • withCredentials: 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.

              Example

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