Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 988 Bytes

README.md

File metadata and controls

45 lines (33 loc) · 988 Bytes

Rest Client for IoTHub

Install the package

npm install https://github.com/joheredi/iothub-rest @azure/identity

Create and authenticate a rest client

import IoTHub from "iotHubClient";
import { DefaultAzureCredential } from "@azure/identity";

const credential = new DefaultAzureCredential();
const client = IoTHub(credential);

Call a simple endpoint

import IoTHub from "iotHubClient";
import { DefaultAzureCredential } from "@azure/identity";

async function main() {
  const subscriptionId = "<Subscription_Id>";
  const credential = new DefaultAzureCredential();
  const client = IoTHub(credential);

  const result = await client
    .path(
      "/subscriptions/{subscriptionId}/providers/Microsoft.Devices/IotHubs",
      subscriptionId
    )
    .get();

  if (result.status !== "200") {
    throw result.body;
  }

  console.log(result.body.value?.map((hub) => hub.name).join("\n"));
}

main().catch(console.error);