Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@actions/http-client

Package Overview
Dependencies
Maintainers
5
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@actions/http-client

Actions Http Client

  • 2.2.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
5
Created

What is @actions/http-client?

The @actions/http-client npm package is designed to provide a simple and efficient way to make HTTP requests from Node.js, particularly within the context of GitHub Actions. It supports features like making GET, POST, and other HTTP requests, handling streams, and processing responses.

What are @actions/http-client's main functionalities?

Making GET requests

This feature allows you to make GET requests to retrieve data from a specified endpoint. The code sample demonstrates how to create an instance of HttpClient, make a GET request, and read the response body.

const { HttpClient } = require('@actions/http-client');
const httpClient = new HttpClient('my-user-agent');

async function getExample() {
  const response = await httpClient.get('https://api.example.com/data');
  const body = await response.readBody();
  console.log(body);
}

getExample();

Making POST requests

This feature allows you to make POST requests to send data to a specified endpoint. The code sample shows how to send a JSON payload with the appropriate headers and process the response.

const { HttpClient } = require('@actions/http-client');
const httpClient = new HttpClient('my-user-agent');

async function postExample() {
  const data = JSON.stringify({ key: 'value' });
  const headers = { 'Content-Type': 'application/json' };
  const response = await httpClient.post('https://api.example.com/submit', data, headers);
  const body = await response.readBody();
  console.log(body);
}

postExample();

Handling streams

This feature is useful for handling large amounts of data by streaming it directly to a file or another destination. The code sample demonstrates how to pipe the response from a GET request into a writable stream.

const { HttpClient } = require('@actions/http-client');
const fs = require('fs');
const httpClient = new HttpClient('my-user-agent');

async function streamExample() {
  const response = await httpClient.get('https://api.example.com/data');
  const stream = fs.createWriteStream('./data.txt');
  response.message.pipe(stream);
}

streamExample();

Other packages similar to @actions/http-client

Keywords

FAQs

Package last updated on 04 Mar 2024

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