Skip to content

Instantly share code, notes, and snippets.

@yassinagx
Forked from faisal00813/messagepack_client.js
Created June 3, 2023 15:56
Show Gist options
  • Save yassinagx/ed98240187b4d41ae65919eb0abbbd62 to your computer and use it in GitHub Desktop.
Save yassinagx/ed98240187b4d41ae65919eb0abbbd62 to your computer and use it in GitHub Desktop.
Client for sending the packed messagepack data to web server
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