Socket
Socket
Sign inDemoInstall

@azure/core-http

Package Overview
Dependencies
Maintainers
1
Versions
300
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@azure/core-http

Isomorphic client Runtime for Typescript/node.js/browser javascript client libraries generated using AutoRest


Version published
Weekly downloads
1.5M
decreased by-10.89%
Maintainers
1
Weekly downloads
 
Created

What is @azure/core-http?

@azure/core-http is a foundational library for making HTTP requests and handling responses in Azure SDKs. It provides a set of utilities and abstractions to simplify the process of interacting with HTTP services, including features like request and response handling, middleware support, and authentication.

What are @azure/core-http's main functionalities?

Making HTTP Requests

This feature allows you to make HTTP requests using the DefaultHttpClient and WebResource classes. The code sample demonstrates how to make a GET request to a public API and log the response.

const { DefaultHttpClient, WebResource } = require('@azure/core-http');

async function makeRequest() {
  const client = new DefaultHttpClient();
  const request = new WebResource('https://jsonplaceholder.typicode.com/posts', 'GET');
  const response = await client.sendRequest(request);
  console.log(response.bodyAsText);
}

makeRequest();

Handling Middleware

This feature allows you to add middleware to the HTTP pipeline. The code sample demonstrates how to add a logging middleware that logs HTTP requests and responses.

const { DefaultHttpClient, WebResource, HttpPipelineLogger, HttpPipelineLogLevel } = require('@azure/core-http');

async function makeRequestWithMiddleware() {
  const client = new DefaultHttpClient({
    requestPolicyFactories: [
      (nextPolicy, options) => new HttpPipelineLogger(nextPolicy, options, HttpPipelineLogLevel.INFO)
    ]
  });
  const request = new WebResource('https://jsonplaceholder.typicode.com/posts', 'GET');
  const response = await client.sendRequest(request);
  console.log(response.bodyAsText);
}

makeRequestWithMiddleware();

Authentication

This feature allows you to handle authentication by using TokenCredentials. The code sample demonstrates how to make an authenticated GET request by setting the Authorization header with a bearer token.

const { DefaultHttpClient, WebResource, TokenCredentials } = require('@azure/core-http');

async function makeAuthenticatedRequest() {
  const token = 'YOUR_ACCESS_TOKEN';
  const credentials = new TokenCredentials(token);
  const client = new DefaultHttpClient();
  const request = new WebResource('https://jsonplaceholder.typicode.com/posts', 'GET');
  request.headers.set('Authorization', `Bearer ${credentials.token}`);
  const response = await client.sendRequest(request);
  console.log(response.bodyAsText);
}

makeAuthenticatedRequest();

Other packages similar to @azure/core-http

Keywords

FAQs

Package last updated on 17 Apr 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc