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

@axway/requester

Package Overview
Dependencies
Maintainers
14
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@axway/requester

Module for HTTP requests

  • 6.2.1
  • joyce
  • irving
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
383
increased by140.88%
Maintainers
14
Weekly downloads
 
Created
Source

@axway/requester

Wrapper around request to provide unified approach of using it across other packages. A HTTP client that supports:

  • keep-alive
  • follow-redirect
  • proxy
  • insecure SSL
  • x-www-form-urlencoded and multipart/form-data forms
  • node engines >= 8.x

Uses the Node.js HTTP module configuration for http.request(options), for example:

const { request } = require('@axway/requester');
const { status, headers, body } = await request({ url: 'http://axway.com' });

Note that this module currently does not support:

  • compression
  • timeouts (apart from default OS)

Installation

npm install @axway/requester

Examples

GET application/json

In this example, the response.body will be automatically JSON decoded.

const { request } = require('@axway/requester');
const response = await request({
	method: 'POST',
	url: 'http://axway.com',
	headers: {
		accept: 'application/json'
	}
});

Options

In this example, the keepAlive option is enabled. When enabled, you should also call destroy to free up sockets.

const { request, destroy } = require('@axway/requester');
const response = await request({
	method: 'POST',
	url: 'http://axway.com',
	headers: {
		accept: 'application/json'
	}
}, {
	keepAlive: true,
	followRedirect: false,
	insecureSSL: true
});
// On shutdown, the keep-alive agents should be destroyed, otherwise they may
// keep connections open on the server unnecessarily.
destroy();

GET text/plain

In this example, the response.body will be automatically JSON decoded with the appropriate charset encoding, or utf-8 if not provided.

const { request } = require('@axway/requester');
const response = await request({
	method: 'POST',
	url: 'http://axway.com',
	headers: {
		accept: 'text/plain'
	}
});

POST application/json

In this example, the body parameter will be automatically JSON encoded, and the content-length will be calculated.

const { request } = require('@axway/requester');
const response = await request({
	method: 'POST',
	url: 'http://axway.com',
	headers: {
		'content-type': 'application/json'
	},
	body: {
		bananas: true
	}
});

POST x-www-form-urlencoded fields

In this cample, the body parameter will be automatically URL encoded, and the content-length will be calculated. Field values can only be primitive types: string, boolean, number, null.

const { request } = require('@axway/requester');
const response = await request({
	method: 'POST',
	url: 'http://axway.com',
	headers: {
		'content-type': 'x-www-form-urlencoded'
	},
	body: {
		bananas: true
	}
});

POST multipart/form-data fields and file

In this cample, the body parameter will be automatically URL encoded, and the content-length and multipart boundary will be calculated. Various options exist for sending multipart data, see form-data for more examples.

const { request } = require('@axway/requester');
const response = await request({
	method: 'POST',
	url: 'http://axway.com',
	headers: {
		'content-type': 'x-www-form-urlencoded'
	},
	body: {
		bananas: true,
		file: {
			filename: 'teapot.png',
			value: fs.createReadStream('teapot.png'),
		}
	}
});

Sending raw form data

Sometimes it is necessary to send raw, pre-encoded data and bypass the default form encoding. In this case, it is possible for body to be a string or Buffer.

const { request } = require('@axway/requester');
const response = await request({
	method: 'PUT',
	url: 'http://axway.com',
	headers: {
		'content-type': 'x-www-form-urlencoded'
	},
	body: 'bananas=true'
});

Sending raw JSON data

Sometimes it is necessary to send raw, pre-encoded data and bypass the default JSON encoding. In this case, it is possible for body to be Buffer.

const { request } = require('@axway/requester');
const response = await request({
	method: 'PUT',
	url: 'http://axway.com',
	headers: {
		'content-type': 'x-www-form-urlencoded'
	},
	body: Buffer.from('{"bananas": true}')
});

API

request(httpOptions, [options])

Make a HTTP request.

  • httpOptions
  • options
    • followRedirects - Follows HTTP redirects. Default: true.
    • insecureSSL - Enables insecure TLS connections. Default: false.
    • keepAlive - Enables HTTP keep-alive. Default: true.
    • limit - Follows HTTP redirects. Default: true.
      • download - Follows HTTP redirects. Default: Infinity.
    • maxRedirects - The maximum number of HTTP redirects to follow before error when followRedirects is enabled. Default: 10.
  • Returns Promise<{status, headers, body}>.

destroy()

Destroys any keep-alive agents that may be in use.

Author

Axway R&D support@axway.com https://axway.com

Changes

6.2.1
  • #7600: Fixed an issue with explicit dependencies, which resulted in not building the dependency tree as expected.
6.2.0
  • #7599: Fixed an issue with the proxy configuration which caused requests to not be correctly routed through the proxy causing request failures.
6.1.0
  • #7595: Update in-house dependencies.
6.0.1
  • #7538: Fixed an issue where the request content-length header was calculated incorrectly when the request body was a string that contains multi-byte characters.
6.0.0
  • #6089: Breaking change: requires minimum Node.js version 16.x.
5.0.5
  • #7538: Fixed an issue where the request content-length header was calculated incorrectly when the request body was a string that contains multi-byte characters.
5.0.4
  • #7412: Pin in-house dependencies.
5.0.3
  • #7411: Internal bump.
5.0.2
  • #7403: Internal dev-dependency change.
5.0.1
  • #7345: Support Node.js 16.
5.0.0
  • #7155: Fixed issue with CVE-2021-3918 and removed the dependency on the request library.
  • #7155: No longer logs outgoing request body at DEBUG level. Instead, it is logged separately at TRACE level.
  • #7155: No longer supports gzip compression.
4.0.7
  • #7105: Removed body payload from DEBUG level log which improves performance.
4.0.6
  • #6934: Internal refactoring around code style.
4.0.5
  • #6315: Internal chore.
4.0.4
  • #6187: Fix README.md input parameter documentation.
4.0.3
  • #6116: Internal cleanup chore.
4.0.2
  • #6114: Refactor code for style, security and performance improvements.
4.0.1
  • #6074: Internal CI chore
4.0.0
  • #5764: Add support for request and response logging using optional logger provided in options.
  • #5764: Breaking change: Removed error property from the response which was always going to be undefined.
3.2.4
  • #5711: Internal cleanup of npm scripts.
3.2.3
  • #5708: Internal changes to update mocha configuration
3.2.2
  • #5707: Internal cleanup to code coverage during build process.
3.2.1
  • #5622: Fix regression introduced in 3.1.1 where the format of the data returned would change depending on the value of the response rather than just the content-type header. Now, when content type is "application/json" and rawBuffer is false, a JSON value will be returned, otherwise it will throw an error while parsing. For other known text-like content-types including "application/xml", a valid string will always be returned. For every other case, a Buffer will be consistently returned.
3.2.0
  • #5630: Support outbound requests with object body as form data including files and streams when using multipart/form-data content type.
  • #5630: Add additional validation to individual payload fields to provide better error messages when using application/x-www-form-urlencoded content type.
3.1.1
  • #5622: Fixed error when the Accept header was a derivative of "application/json" and 0 length response body was returned.
3.1.0
  • #5329: Support outbound requests with object body as form data when using application/x-www-form-urlencoded content type.
3.0.0
  • #5432: Previously, the requester was encoding and decoding the payload assuming it was of type application/json. Now, it respects the provided content type.
2.1.0
  • #5364: Support insecure SSL option on outbound requests insecureSSL.
2.0.0
  • #4919: Requester now is just a tiny wrapper around the request module. It has no business logic within it.

  • #4918: Breaking change: Previously, if a request to a method which documented an optional query parameter with a default value and was not supplied to the request, the default value would be sent to the service instead. Now, default values are not used when sending query parameters.

  • #4918: Breaking change: Removed support for the following credential configuration values. Authorization parameters should be provided in authorizationData instead:

    • x-vendor-openapi-username
    • x-vendor-openapi-password
    • x-vendor-openapi-key
    • x-vendor-openapi-token
  • #4918: Added support for authorization parameters, replacing x-vendor-openapi- global configuration. These parameters are generated based on the security parameter in the original swagger document.

1.1.2
  • #4757: Changed SCM repository and associated internal cleanup.

License

This code is proprietary, closed source software licensed to you by Axway. All Rights Reserved. You may not modify Axway’s code without express written permission of Axway. You are licensed to use and distribute your services developed with the use of this software and dependencies, including distributing reasonable and appropriate portions of the Axway code and dependencies. Except as set forth above, this code MUST not be copied or otherwise redistributed without express written permission of Axway. This module is licensed as part of the Axway Platform and governed under the terms of the Axway license agreement (General Conditions) located here: https://support.axway.com/en/auth/general-conditions; EXCEPT THAT IF YOU RECEIVED A FREE SUBSCRIPTION, LICENSE, OR SUPPORT SUBSCRIPTION FOR THIS CODE, NOTWITHSTANDING THE LANGUAGE OF THE GENERAL CONDITIONS, AXWAY HEREBY DISCLAIMS ALL SUPPORT AND MAINTENANCE OBLIGATIONS, AS WELL AS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO IMPLIED INFRINGEMENT WARRANTIES, WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, AND YOU ACCEPT THE PRODUCT AS-IS AND WITH ALL FAULTS, SOLELY AT YOUR OWN RISK. Your right to use this software is strictly limited to the term (if any) of the license or subscription originally granted to you.

Keywords

FAQs

Package last updated on 10 Nov 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