Socket
Socket
Sign inDemoInstall

sync-request

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sync-request

Make synchronous web requests


Version published
Weekly downloads
944K
increased by4.69%
Maintainers
1
Weekly downloads
 
Created

What is sync-request?

The sync-request npm package allows you to make synchronous HTTP requests in Node.js. This can be useful for scenarios where you need to ensure that a request completes before moving on to the next line of code, although it is generally recommended to use asynchronous requests to avoid blocking the event loop.

What are sync-request's main functionalities?

GET Request

This feature allows you to make a synchronous GET request to a specified URL. The response body can be accessed and logged.

const request = require('sync-request');
const res = request('GET', 'https://jsonplaceholder.typicode.com/posts/1');
console.log(res.getBody('utf8'));

POST Request

This feature allows you to make a synchronous POST request with a JSON payload. The response body can be accessed and logged.

const request = require('sync-request');
const res = request('POST', 'https://jsonplaceholder.typicode.com/posts', {
  json: { title: 'foo', body: 'bar', userId: 1 }
});
console.log(res.getBody('utf8'));

Custom Headers

This feature allows you to make a synchronous GET request with custom headers. The response body can be accessed and logged.

const request = require('sync-request');
const res = request('GET', 'https://jsonplaceholder.typicode.com/posts/1', {
  headers: {
    'User-Agent': 'request'
  }
});
console.log(res.getBody('utf8'));

Other packages similar to sync-request

Keywords

FAQs

Package last updated on 17 Mar 2019

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