Leverage the performance of the native gRPC libraries in your React Native app.
If you wanted to use gRPC in a React Native app you would need to use either grpc-web with a proxy infront or make a custom native implemtation of the gRPC libraries for iOS and Android, which can be cumbersome at best.
Now you can utilize the power of the native libraries right in your javascript, powered by protoc code generation.
This implementation utilizes the protoc protobuf compilers ability to generate native and Javascript code. The generated code will communicate with each other through the NativeModule interface provided by React Native. This way you can freely communicate with your gRPC backend via Javascript code, without thinking about proxies or other extra worries.
First of all, you should install the dependencies of the generated code.
The Javascript code generator depends on these NPM packages that you have to install before generating any code:
npm install bla bla --save
Also, install these if you are using Typescript:
npm install bla bla --save-dev
Before installing anything, go and add a dummy empty swift file to your project (make sure your app is targeted). Xcode will ask you to create an Objective-C bridging Header. Doing this step prior to installing any Swift dependencies solves some potential build issues. You will also need the bridging header for later
You will need to install grpc-swift into your React Native Xcode project. Do this via the swift package manager under Project > Swift Package Manager and add the url to the above mentioned grpc-swift git repository.
Not yet implemented. Feel free to submit a pull with a code generator and docs!
For generating all the necessary code, you will need the three (currently only JS and Swift is implemented) plugins from this repository, and a few others
-
protoc-gen-swiftUsed for generating the Swift message stubs. Read more...
-
protoc-gen-grpc-swiftUsed for generating the Swift gRPC client stubs. Read more...
-
protoc-gen-rn-grpc-swiftUsed for generating iOS native briding infrastructure. Exposes low level gRPC access to the Javascript of your app. Read more...
-
protoc-gen-jsUsed for generating Javascript message stubs. Read more...
-
protoc-gen-ts(Optional)Used in conjunction with
protoc-gen-js. Generates Typescript definitions for the message stubs. Read more... -
protoc-gen-rn-grpc-jsUsed for generating Javascript gRPC client stubs. Exposes a high level access to the Native briding infrastructure. Can expose Typescript definitions as well. Read more...
-
... other plugins for Android (not yet implemented)