Created
September 11, 2020 00:47
-
-
Save leleofg/60801e6df49ed12376a131d47338d599 to your computer and use it in GitHub Desktop.
Client gRPC
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 grpc = require("grpc"); | |
const protoLoader = require("@grpc/proto-loader"); | |
const PROTO_PATH = __dirname + "/proto/user.proto"; | |
const packageDefinition = protoLoader.loadSync(PROTO_PATH, { | |
keepCase: true, | |
defaults: true, | |
oneofs: true, | |
}); | |
const protos = grpc.loadPackageDefinition(packageDefinition); | |
function main() { | |
const client = new protos.UserService( | |
"localhost:50051", | |
grpc.credentials.createInsecure() | |
); | |
client.createUser( | |
{ email: "[email protected]", username: "leo", passsword: "123456" }, | |
function (err, response) { | |
console.log("Response:", response); | |
} | |
); | |
client.getUserById({ id: 123 }, function (err, response) { | |
console.log("Response:", response); | |
}); | |
} | |
main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment