0.2.5 • Published 1 year ago

jd_rest_cli v0.2.5

Weekly downloads
5
License
ISC
Repository
github
Last release
1 year ago

Class to perform REST Requests

Usage

RestCli = require('jd-rest-cli');

RestCli.get( "http://my.domain.com/api/test" )
.opts({timeout : 20}) 
.headers( { authorization : "Bearer 1234" } )
.query( { search : "something") } )
.send()
.then( r => { console.log(` StatusCode : ${res.statusCode}\n${res.body}\n${JSON.stringify(res.headers)}`); })

RestCli.get( "http://my.domain.com/api/test" )
.form({ input1 : 1, input2 : 2})
.send()
.then( r => { console.log(` StatusCode : ${res.statusCode}\n${res.body}\n${JSON.stringify(res.headers)}`); })

RestCli.get( "http://my.domain.com/api/test" )
.json({
    jsonBodyAttr1: 1,
    jsonBodyAttr2: "tata"
})
.send()
.then( r => { return r; })


RestCli.get( "http://my.domain.com/api/test" )
.send("Something")
.then( r => { return r; })

Possibility to set an external Authorization Header handler (async)

RestCli.setAuthHandler(async function() { return "Bearer MyComputedBearer})
// and to inhibit for a specific call (for exemple the one to retrieve external AccessToken)
RestCli.post("http://localhost").noauth().send();

return object with

  • statusCode : int
  • headers : object
  • body : (mixed) : converted to JSON if response content-type contains json
0.2.5

1 year ago

0.2.4

2 years ago

0.2.1

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.0

3 years ago

0.1.9

3 years ago

0.1.7

4 years ago

0.1.6

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.1

4 years ago

0.0.5

4 years ago