Last active
June 3, 2023 15:56
-
-
Save faisal00813/c8028de3e4a37f1ce92edc443d3aba8c to your computer and use it in GitHub Desktop.
Client for sending the packed messagepack data to web server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const request = require('request') | |
const msgpack = require("msgpack-lite"); | |
var packedData = msgpack.encode({ | |
"str" : "Something", | |
"number" : 4.0, | |
"arr": ["one","two"], | |
"nClass": { | |
"doubleNumber" : 35.0, | |
"nums" : [34,23] | |
}, | |
"bool":true | |
}); | |
request.post( | |
{ | |
url:'http://localhost:9000/user/msgPackTest', | |
headers: { | |
'content-type': 'application/octet-stream' | |
}, | |
body: packedData, | |
encoding: null | |
}, function optionalCallback(err, httpResponse, body) { | |
if (err) { | |
return console.error('upload failed:', err); | |
} | |
console.log('Upload successful! Server responded with:', msgpack.decode(body)); | |
}); | |
// package.json | |
// ---------- | |
// { | |
// "name": "msgpack_webserver", | |
// "version": "1.0.0", | |
// "description": "", | |
// "main": "index.js", | |
// "scripts": { | |
// "test": "echo \"Error: no test specified\" && exit 1" | |
// }, | |
// "author": "", | |
// "license": "ISC", | |
// "dependencies": { | |
// "msgpack-lite": "^0.1.26", | |
// "request": "^2.83.0" | |
// } | |
// } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment