Azure IoT HTTP Base Library

1.12.3 · active · verified Wed Apr 22

The `azure-iot-http-base` package is an internal library within the Azure IoT Node.js SDKs, providing foundational HTTP-specific components and utilities. It is not intended for direct consumption by most application developers; instead, its functionalities are integrated and exposed through higher-level SDK packages such as `azure-iot-device-http` for device clients and `azure-iothub` for service clients. The current stable version is 1.12.3, released as part of the broader Azure SDKs for Node.js update cadence, which typically occurs every few months. Key differentiators include its specialized focus on HTTP operations within the Azure IoT ecosystem, its role as a low-level transport primitive, and its inclusion of TypeScript type definitions, ensuring robust development practices. It abstracts away the complexities of HTTP communication for IoT-specific scenarios, supporting Node.js versions 14.0.0 and above. Developers should generally rely on the orchestrating device or service SDKs for HTTP-based interactions, as this package handles the underlying mechanics.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to instantiate and use `HttpsClient` for a basic GET request, highlighting that this is an internal library not typically for direct consumption by end-user applications.

import { HttpsClient, RequestOptions, RequestAndResponse } from 'azure-iot-http-base';
import { URL } from 'url';

// WARNING: This package is an internal library and direct usage is generally discouraged.
// Most developers should use higher-level Azure IoT SDKs like 'azure-iot-device-http'
// or 'azure-iothub' which manage these transport details.

async function makeSimpleHttpRequest() {
  console.log('Attempting a low-level HTTP GET request using azure-iot-http-base (for demonstration purposes only)...');

  const client = new HttpsClient();
  const url = new URL('https://httpbin.org/get?source=azure-iot-http-base-demo');

  const requestOptions: RequestOptions = {
    method: 'GET',
    url: url.toString(),
    headers: { 'User-Agent': 'Azure-IoT-HTTP-Base-Demo/1.0' }
  };

  try {
    const response: RequestAndResponse = await client.sendRequest(requestOptions);
    console.log(`\nHTTP Status: ${response.statusCode}`);
    console.log(`Response Headers: ${JSON.stringify(response.headers, null, 2)}`);
    console.log(`Response Body (truncated): ${response.body?.toString().substring(0, 200)}...`);
  } catch (error: any) {
    console.error(`\nError making HTTP request: ${error.message}`);
    if (error.response) {
      console.error(`Status: ${error.response.statusCode}`);
      console.error(`Body: ${error.response.body?.toString()}`);
    }
  }
}

makeSimpleHttpRequest().catch(console.error);

view raw JSON →