๐Ÿ  Home > ๐Ÿ’ป Code Examples > ๐ŸŸจ JavaScript Client

JavaScript/Node.js Client Implementation

Installation

npm install axios crypto

Complete Client Class

const axios = require('axios');
const crypto = require('crypto');

class StatHQClient {
  constructor(serviceUrl, serviceName, secret) {
    this.serviceUrl = serviceUrl;
    this.serviceName = serviceName;
    this.secret = secret;
  }

  createSign(plan) {
    const hash = crypto.createHash('sha256');
    hash.update(plan + this.secret);
    return hash.digest('base64');
  }

  async callMethod(methodName, params) {
    const soapEnvelope = this.buildSoapEnvelope(methodName, params);

    const response = await axios.post(this.serviceUrl, soapEnvelope, {
      headers: {
        'Content-Type': 'text/xml; charset=utf-8',
        'SOAPAction': `"http://tempuri.org//${methodName}"`
      }
    });

    return this.parseSoapResponse(response.data);
  }

  buildSoapEnvelope(methodName, params) {
    // Implementation here
  }

  parseSoapResponse(xmlString) {
    // Parse XML response
  }
}

module.exports = StatHQClient;

โฌ…๏ธ Back to Code Examples | ๐Ÿ  API Overview | ๐Ÿ“Š Data Types

results matching ""

    No results matching ""