
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Fast, simple, powerfull rest client for node.
var trestcjs = require('trestcjs')
var options = {resdecod:{type:'json'}}
trestcjs.http_get('www.domain.com',80,'',null,null,options,function(error,response){});
$ npm install trestcjs
General Rest request:
trestcjs.OPERATION(host,port,path,pathparams,data,options,callback);
trestcjs.http_get(host,port,path,pathparams,options,callback); //No Data. Also https_get
trestcjs.http(method,host,port,path,pathparams,data,options,callback);//Added parameter method. Also https
Valid operations are:
If you want to make a PUT request to http://www.domain.com/path/to/resource?value=1&other=2 with xml data : value value just:
var trestcjs = require('trestcjs')
var options = {reqdecod:{type:'xml',xmlhead:'node'}}
var pathparams = {value:1,other:2}
var data = {node1:value,node2:value}
trestcjs.http_put('www.domain.com',80,/path/to/resource,options,null,pathparams,function(error,response){
//Response here...
});
Other Example. If you want to make a POST with a form with data a=1 and b = 2 to http://www.domain.com/path/to/resource:
var trestcjs = require('trestcjs')
var options = {reqdecod:{type:'form'}}
var data = {a:1,b:2}
trestcjs.http_post('www.domain.com',80,/path/to/resource,options,null,pathparams,function(error,response){
//Response here...
});
trestcjs has several options parameters. All of them are object (except trace that is boolean) and can be included in options or not (they are not mandatory)
trestcjs allow custom header parameter. Any parameter that you include in the object header will include in the header of request. For example you can set headers['SOAPAction'] = 'blabla' and this parameter will be received from server in headers. Remember that http headers are case INsensitive. One aclaration, by default, trestcjs include the parameter 'accept-encoding' as 'gzip, deflate' but you can rewrite including this parameter in header or removing just setting to '' => headers['accept-encoding'] = ''
Right now the only supported authorization method is Basic Auth, you set it as:
auth : {
type : 'basic',
username: 'your username',
password: 'your password'
}
You can include cert key/secret and even cert authority:
cert : {
key: 'local/path/to/key',
cert: 'local/path/to/cert',
ca: 'local/path/to/ca'
}
More information in the official node documentation: https://nodejs.org/api/tls.html
This object allow configure request decoding (data and text). Fields:
reqdecod : {
type: 'xml', //Valid xml, json, form and direct
encoding: 'utf-8' //text encoding of request
}
If you set reqdecod.type, system will use this as a data converter and will set automatically content-type. If you don't set this, check if you set content-type and if not just assign direct Allowed encoding:
Same as reqdecod. If type is not set, check content-type in headers of response
resdecod : {
type: 'xml', //Valid xml, json, form and direct
encoding: 'utf-8' //text encoding of request
}
If you set this field in options and set as true, the callback of response will include two extrafields : statusCode and trace. Trace is an object with all data/headers/information of request and response with:
trace : {
req: {} // Object with request data
res: {} //Object with response data
}
If you want to include your own asyncronous log, you have to set this field with the "log tag" you want for the current request.
log : {
tag: "YourRulesTag" // Your custom tag to identify request
}
Custom log will be explained later
Callback will have 2 or 4 parameters: error,data[,statusCode,trace] when statusCode or trace only will be included if trace=true or log.tag exists.
{
code //The error code
msg //Message of this error
(info) //Extra info of error, not mandatory
(statusCode) //Error received from server (4XX,5XX). If trestcjs doesnt receive response (timeout or unreachable) then this field will not exists
}
Is possible to create a custom and async log procedure. If you set log.tag in a request, trestcjs will emit two events: "requestStart" and "requestEnd" when request is sended and response is received (respectively). To subscribe to event just:
trestcjs.on('requestStart',function(tag,trace){
});
tag is log.tag you assign to request, trace is equal to trace in callback but only trace.req or trace.res depending on if is requestStart Event or requestEnd event
First version in client with all features
FAQs
Simple Rest client for node
The npm package trestcjs receives a total of 2 weekly downloads. As such, trestcjs popularity was classified as not popular.
We found that trestcjs 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.