Security News
Research
Supply Chain Attack on Rspack npm Packages Injects Cryptojacking Malware
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
elasticio-node
Advanced tools
The following example demonstrates the most simple component sending a GET request to a HTTP resource. This is accomplished by defining request options and passing them to HttpComponent.get
.
var HttpComponent = require('elasticio-node').HttpComponent;
// exporting the process function to be called by elastic.io runtime
exports.process = doProcess;
function doProcess(msg, cfg) {
// creating requestion options
var options = {
url: 'http://foobarbazbarney.com/api',
json: true
};
// sending GET request with given options
new HttpComponent(this).get(options);
}
Please note that HttpComponent.get
sends a HTTP GET request. The response is checked to have a status codes 200 OK
or 201 Created
. If so, the response's body will be be used as component's output. Any other status code will result in an error being thrown.
The HttpComponent
class exposes function for each of the supported HTTP verbs. Currently following are supported:
HttpComponent.get
: sends HTTP GETHttpComponent.post
: sends HTTP POSTHttpComponent.put
: sends HTTP PUTHere is an example of how to send a HTTP POST request:
var HttpComponent = require('elasticio-node').HttpComponent;
// exporting the process function to be called by elastic.io runtime
exports.process = doProcess;
function doProcess(msg, cfg) {
// creating requestion options
var options = {
url: 'http://foobarbazbarney.com/api',
body : JSON.stringify({message : "Hello, world!"})
};
// sending GET request with given options
new HttpComponent(this).post(options);
}
HTTP Headers for the request can be set in the options object:
// creating requestion options
var options = {
url: 'http://foobarbazbarney.com/api',
json : {message : "Hello, world!"},
headers: {
'Authorization': 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==',
'Accept-Charset': 'utf-8',
'User-Agent': 'Mozilla/5.0'
}
};
var elasticio = require('elasticio-node');
var HttpComponent = elasticio.HttpComponent;
var messages = elasticio.messages;
exports.process = doProcess;
function doProcess(msg, cfg) {
var self = this;
// creating requestion options
var options = {
url: 'http://foobarbazbarney.com/api',
json: true
};
// overrides the default response handler
function onSuccess(response, body) {
if (response.statusCode === 400) {
throw new Error(JSON.stringify(body));
}
// you may also modify the data before emitting them
delete body.internalId;
// creating a message from given response body
var data = messages.newMessageWithBody(body);
// emitting the "data" event
self.emit('data', data);
}
// sending GET request with given options
new HttpComponent(this).success(onSuccess).get(options);
}
FAQs
Node.js API for the elastic.io integration platform
The npm package elasticio-node receives a total of 619 weekly downloads. As such, elasticio-node popularity was classified as not popular.
We found that elasticio-node demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
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.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.
Security News
Sonar’s acquisition of Tidelift highlights a growing industry shift toward sustainable open source funding, addressing maintainer burnout and critical software dependencies.