Unirest is a set of lightweight HTTP libraries available in multiple languages, built and maintained by Kong, who also maintain the open-source API Gateway Kong.
npm install unirest
unirest
.post('http://mockbin.com/request')
.headers({'Accept': 'application/json', 'Content-Type': 'application/json'})
.send({ "parameter": 23, "foo": "bar" })
.then((response) => {
console.log(response.body)
})
Uploading Files
unirest
.post('http://mockbin.com/request')
.headers({'Content-Type': 'multipart/form-data'})
.field('parameter', 'value') // Form field
.attach('file', '/tmp/file') // Attachment
.then(function (response) {
console.log(response.body)
})
Custom Entity Body
unirest
.post('http://mockbin.com/request')
.headers({'Accept': 'application/json'})
.send(Buffer.from([1,2,3]))
.then(function (response) {
console.log(response.body)
}
references:
https://github.com/Kong/unirest-nodejs
No comments:
Post a Comment