Advertisement
aldikhan13

GRPC Protofile Property Explained

May 15th, 2022 (edited)
2,267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Smarty 1.56 KB | None | 0 0
  1. # Protofile Property Explained
  2.  
  3. **int32, string, bool**: digunakan untuk menentukan type data dari setiap request atau response yang di buat, silahkan cek doc untuk refensi type data yang didukung -> https://developers.google.com/protocol-buffers/docs/reference/overview
  4.  
  5. **syntax**: digunakan untuk menentukan versi sintak yang didukung saat menulis schema
  6.  
  7. **package**: digunakan sebagai penamaan (label) untuk proto schema
  8.  
  9. **import**: digunakan untuk memanggil setiap fungsi yang sudah disediakan oleh grpc
  10.  
  11. **rpc**: digunakan sebagai layanan untuk berkomunikasi dari server ke client untuk menghandle sebuah request/response
  12.  
  13. **service**: digunakan sebagai namespace/constructor untuk memanggil rcp method (resolvers)
  14.  
  15. **message**: digunakan untuk membuat request/response untuk rpc method (resolvers)
  16.  
  17. **repeated**: digunakan untuk memperbanyak data, biasa digunakan untuk menghandle data array atau array of object
  18.  
  19. **returns**: digunakan untuk meneruskan sebuah response yang di teruskan dari rpc method (resolvers)
  20.  
  21. # Example Proto Schema
  22.  
  23. syntax = "proto3"; -> tipe version protobuffer schema
  24.  
  25. package student;
  26.  
  27. import "google/protobuf/empty.proto";
  28.  
  29. service Student {
  30.   rpc ResultsStudent(google.protobuf.Empty) returns (StudentList) {}
  31. }
  32.  
  33. message StudentList {
  34.   repeated StudentRequest students = 1;
  35.   int32 statusCode = 2;
  36.   string message = 3;
  37. }
  38.  
  39. # Tutorial grpc
  40.  
  41. https://github.com/restuwahyu13/express-grpc-rest-api - me
  42. https://github.com/restuwahyu13/node-grpc-typescript - me
  43. https://github.com/uid4oe/microservices-go-grpc - not me
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement