diff --git a/content/docs/quickstart/android.md b/content/docs/quickstart/android.md index 858821d..8199ef6 100644 --- a/content/docs/quickstart/android.md +++ b/content/docs/quickstart/android.md @@ -7,26 +7,25 @@ description: This guide gets you started with gRPC in Android Java with a simple
-### Before you begin +### Prerequisites -#### Prerequisites +- JDK version 7 or higher +- Android SDK, API level 14 or higher +- An android device set up for [USB debugging][] or an + [Android Virtual Device][] -* JDK: version 7 or higher -* Android SDK: API level 14 or higher -* An android device set up for [USB - debugging](https://developer.android.com/studio/command-line/adb.html#Enabling) - or an [Android Virtual - Device](https://developer.android.com/studio/run/managing-avds.html) +[Android Virtual Device]: https://developer.android.com/studio/run/managing-avds.html +[USB debugging]: https://developer.android.com/studio/command-line/adb.html#Enabling -Note: gRPC Java does not support running a server on an Android device. For this -quickstart, the Android client app will connect to a server running on your -local (non-Android) computer. +> **Note**: gRPC Java does not support running a server on an Android device. +> For this quick start, the Android client app will connect to a server running +> on your local (non-Android) computer. ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh @@ -38,19 +37,19 @@ $ cd grpc-java/examples ### Run a gRPC application - 1. Compile the server + 1. Compile the server: ```sh $ ./gradlew installDist ``` - 2. Run the server + 2. Run the server: ```sh $ ./build/install/examples/bin/hello-world-server ``` - 3. In another terminal, compile and run the client + 3. From another terminal, compile and run the client: ```sh $ cd android/helloworld @@ -111,7 +110,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Update and run the application @@ -125,7 +124,7 @@ parts of our example application. #### Update the server -Check out the Java quickstart [here](/docs/quickstart/java/#update-the-server). +See the [Java quick start](/docs/quickstart/java/#update-the-server). #### Update the client @@ -134,17 +133,17 @@ In the same directory, open method like this: ```java - try { - HelloRequest message = HelloRequest.newBuilder().setName(mMessage).build(); - HelloReply reply = stub.sayHello(message); - reply = stub.sayHelloAgain(message); - } catch (Exception e) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - pw.flush(); - return "Failed... : " + System.lineSeparator() + sw; - } +try { + HelloRequest message = HelloRequest.newBuilder().setName(mMessage).build(); + HelloReply reply = stub.sayHello(message); + reply = stub.sayHelloAgain(message); +} catch (Exception e) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + pw.flush(); + return "Failed... : " + System.lineSeparator() + sw; +} ``` #### Run! @@ -157,13 +156,13 @@ Just like we did before, from the `examples` directory: $ ./gradlew installDist ``` - 2. Run the server + 2. Run the server: ```sh $ ./build/install/examples/bin/hello-world-server ``` - 3. In another terminal, compile and install the client to your device + 3. From another terminal, compile and install the client to your device ```sh $ cd android/helloworld diff --git a/content/docs/quickstart/cpp.md b/content/docs/quickstart/cpp.md index 4e872c7..ba7e6f2 100644 --- a/content/docs/quickstart/cpp.md +++ b/content/docs/quickstart/cpp.md @@ -7,9 +7,9 @@ description: This guide gets you started with gRPC in C++ with a simple working
-### Before you begin +### Prerequisites -#### Install gRPC +#### gRPC To install gRPC on your system, follow the [instructions to install gRPC C++ via make](https://github.com/grpc/grpc/blob/master/src/cpp/README.md#make). @@ -19,7 +19,7 @@ example `Makefile`s try to look up the installed gRPC path using `pkg-config`. On Debian-based systems like Ubuntu, this can usually be done via `sudo apt-get install pkg-config`. -#### Install Protocol Buffers v3 +#### Protocol Buffers v3 While not mandatory to use gRPC, gRPC applications usually leverage Protocol Buffers v3 for service definitions and data serialization, and our example code @@ -55,11 +55,13 @@ instructions for details](https://github.com/grpc/grpc/blob/master/src/cpp/READM From the `examples/cpp/helloworld` directory, run the server, which will listen on port 50051: + ```sh $ ./greeter_server ``` From a different terminal, run the client: + ```sh $ ./greeter_client ``` @@ -69,7 +71,6 @@ client side output. Congratulations! You've just run a client-server application with gRPC. - ### Update a gRPC service Now let's look at how to update the application with an extra method on the @@ -81,7 +82,6 @@ C++](/docs/tutorials/basic/cpp/). For now all you need to know is that both the the client and returns a `HelloResponse` from the server, and that this method is defined like this: - ```protobuf // The greeting service definition. service Greeter { @@ -105,7 +105,6 @@ Let's update this so that the `Greeter` service has two methods. Edit update it with a new `SayHelloAgain` method, with the same request and response types: - ```protobuf // The greeting service definition. service Greeter { @@ -126,7 +125,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Generate gRPC code @@ -151,7 +150,6 @@ and call the new method in the human-written parts of our example application. In the same directory, open `greeter_server.cc`. Implement the new method like this: - ```c++ class GreeterServiceImpl final : public Greeter::Service { Status SayHello(ServerContext* context, const HelloRequest* request, @@ -223,28 +221,27 @@ int main(int argc, char** argv) { Just like we did before, from the `examples/cpp/helloworld` directory: -1. Build the client and server after having made changes: + 1. Build the client and server after having made changes: ```sh $ make ``` -2. Run the server + 2. Run the server: ```sh $ ./greeter_server ``` -3. On a different terminal, run the client + 3. On a different terminal, run the client: ```sh $ ./greeter_client ``` - You should see the updated output: + You'll see the following output: ```sh - $ ./greeter_client Greeter received: Hello world Greeter received: Hello again world ``` @@ -252,7 +249,7 @@ Just like we did before, from the `examples/cpp/helloworld` directory: ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) -- Work through a more detailed tutorial in [gRPC Basics: C++](/docs/tutorials/basic/cpp/) + and [gRPC Concepts](/docs/guides/concepts/). +- Work through a more detailed tutorial in [gRPC Basics: C++](/docs/tutorials/basic/cpp/). - Explore the gRPC C++ core API in its [reference - documentation](/grpc/cpp/) + documentation](/grpc/cpp/). diff --git a/content/docs/quickstart/csharp-dotnet.md b/content/docs/quickstart/csharp-dotnet.md index 798afb7..20c743a 100644 --- a/content/docs/quickstart/csharp-dotnet.md +++ b/content/docs/quickstart/csharp-dotnet.md @@ -7,8 +7,9 @@ description: This guide gets you started with gRPC for .NET with a simple workin
-NOTE: This is a quick start guide for the "grpc-dotnet" implementation of gRPC C#s. -See [gRPC C# Quick Start](/docs/quickstart/csharp) for how to start with the gRPC C# implementation based on native Core library. +> **Note**: This is a quick start guide for the "grpc-dotnet" implementation of +> gRPC C#s. See [gRPC C# Quick Start](/docs/quickstart/csharp) for how to start +> with the gRPC C# implementation based on native Core library. ### General project info diff --git a/content/docs/quickstart/csharp.md b/content/docs/quickstart/csharp.md index d098427..570746d 100644 --- a/content/docs/quickstart/csharp.md +++ b/content/docs/quickstart/csharp.md @@ -7,12 +7,12 @@ description: This guide gets you started with gRPC in C# with a simple working e
-NOTE: This is a quick start guide for the gRPC C# implementation based on Core native library. -See [gRPC for .NET Quick Start](/docs/quickstart/csharp-dotnet/) for how to start with the "grpc-dotnet" implementation. +> **Note**: This is a quick start guide for the gRPC C# implementation based on +> Core native library. See [gRPC for .NET Quick +> Start](/docs/quickstart/csharp-dotnet/) for how to start with the +> "grpc-dotnet" implementation. -### Before you begin - -#### Prerequisites +### Prerequisites Whether you're using Windows, OS X, or Linux, you can follow this example by using either an IDE and its build tools, @@ -24,14 +24,14 @@ You will also need Git to download the sample code. ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh -$ # Clone the repository to get the example code: -$ git clone -b {{< param grpc_release_tag >}} https://github.com/grpc/grpc +# Clone the repository to get the example code: +$ git clone -b {{< param grpc_release_tag >}} https://github.com/grpc/grpc $ cd grpc ``` @@ -61,14 +61,14 @@ From the `examples/csharp/Helloworld` directory: From the `examples/csharp/Helloworld` directory: -* Run the server +* Run the server: ```sh > cd GreeterServer > dotnet run -f netcoreapp2.1 ``` -* In another terminal, run the client +* From another terminal, run the client: ```sh > cd GreeterClient @@ -130,11 +130,11 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Generate gRPC code -Next we need to update the gRPC code used by our application to use the new service definition. +Next we need to update the gRPC code used by our application to use the new service definition. The `Grpc.Tools` NuGet package contains the protoc and protobuf C# plugin binaries needed to generate the code. Starting from version 1.17 the package also integrates with @@ -158,7 +158,7 @@ under the `Greeter/obj/Debug/TARGET_FRAMEWORK` directory: Greeter service implementations * a class `Greeter.GreeterClient` that can be used to access remote Greeter instances - + ### Update and run the application We now have new generated server and client code, but we still need to implement @@ -201,7 +201,7 @@ public static void Main(string[] args) var reply = client.SayHello(new HelloRequest { Name = user }); Console.WriteLine("Greeting: " + reply.Message); - + var secondReply = client.SayHelloAgain(new HelloRequest { Name = user }); Console.WriteLine("Greeting: " + secondReply.Message); @@ -220,24 +220,24 @@ example by running `dotnet build Greeter.sln` or by clicking "Build" in Visual S Just like we did before, from the `examples/csharp/Helloworld` directory: -* Run the server + 1. Run the server: -```sh -> cd GreeterServer -> dotnet run -f netcoreapp2.1 -``` + ```sh + > cd GreeterServer + > dotnet run -f netcoreapp2.1 + ``` -* In another terminal, run the client + 2. From another terminal, run the client: -```sh -> cd GreeterClient -> dotnet run -f netcoreapp2.1 -``` + ```sh + > cd GreeterClient + > dotnet run -f netcoreapp2.1 + ``` ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) -- Work through a more detailed tutorial in [gRPC Basics: C#](/docs/tutorials/basic/csharp/) + and [gRPC Concepts](/docs/guides/concepts/). +- Work through a more detailed tutorial in [gRPC Basics: C#](/docs/tutorials/basic/csharp/). - Explore the gRPC C# core API in its [reference - documentation](/grpc/csharp/api/Grpc.Core.html) \ No newline at end of file + documentation](/grpc/csharp/api/Grpc.Core.html). diff --git a/content/docs/quickstart/dart.md b/content/docs/quickstart/dart.md index d6b23c2..d45769d 100644 --- a/content/docs/quickstart/dart.md +++ b/content/docs/quickstart/dart.md @@ -9,12 +9,12 @@ description: This guide gets you started with gRPC in Dart with a simple working ### Prerequisites -#### Dart SDK - -gRPC requires Dart SDK version 2.0 or higher. Dart gRPC supports Flutter and Server platforms. +- Dart SDK version 2.0 or higher. For installation instructions, see [Install Dart](https://dart.dev/install). +> Note: Dart gRPC supports the Flutter and Server platforms. + #### Protocol Buffers v3 While not mandatory to use gRPC, gRPC applications usually leverage Protocol @@ -44,9 +44,9 @@ $ export PATH=$PATH:$HOME/.pub-cache/bin ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh @@ -66,13 +66,13 @@ From the `example/helloworld` directory: $ pub get ``` - 2. Run the server + 2. Run the server: ```sh $ dart bin/server.dart ``` - 3. In another terminal, run the client + 3. From another terminal, run the client: ```sh $ dart bin/client.dart @@ -205,25 +205,25 @@ Future main(List args) async { Run the client and server like you did before. Execute the following commands from the `example/helloworld` directory: - 1. Run the server + 1. Run the server: ```sh $ dart bin/server.dart ``` - 2. In another terminal, run the client. This time, add a name as a command-line + 2. From another terminal, run the client. This time, add a name as a command-line argument: ```sh $ dart bin/client.dart Alice ``` -You should see the following output in the client terminal: + You'll see the following output: -```sh -Greeter client received: Hello, Alice! -Greeter client received: Hello again, Alice! -``` + ```sh + Greeter client received: Hello, Alice! + Greeter client received: Hello again, Alice! + ``` ### What's next diff --git a/content/docs/quickstart/go.md b/content/docs/quickstart/go.md index 049aa64..850f163 100644 --- a/content/docs/quickstart/go.md +++ b/content/docs/quickstart/go.md @@ -9,17 +9,11 @@ description: This guide gets you started with gRPC in Go with a simple working e ### Prerequisites -#### Go version +- Go version 1.6 or higher. -gRPC requires Go 1.6 or higher. +For installation instructions, see Go's [Getting Started](https://golang.org/doc/install) guide. -```sh -$ go version -``` - -For installation instructions, follow this guide: [Getting Started - The Go Programming Language](https://golang.org/doc/install) - -#### Install gRPC +#### gRPC Use the following command to install gRPC. @@ -27,7 +21,7 @@ Use the following command to install gRPC. $ go get -u google.golang.org/grpc ``` -#### Install Protocol Buffers v3 +#### Protocol Buffers v3 Install the protoc compiler that is used to generate gRPC service code. The simplest way to do this is to download pre-compiled binaries for your platform(`protoc--.zip`) from here: [https://github.com/google/protobuf/releases](https://github.com/google/protobuf/releases) @@ -40,7 +34,9 @@ Next, install the protoc plugin for Go $ go get -u github.com/golang/protobuf/protoc-gen-go ``` -The compiler plugin, protoc-gen-go, will be installed in $GOBIN, defaulting to $GOPATH/bin. It must be in your $PATH for the protocol compiler, protoc, to find it. +The compiler plugin, `protoc-gen-go`, will be installed in `$GOBIN`, defaulting +to `$GOPATH/bin`. It must be in your `PATH` for the protocol compiler, protoc, +to find it. ```sh $ export PATH=$PATH:$GOPATH/bin @@ -58,14 +54,19 @@ Change to the example directory $ cd $GOPATH/src/google.golang.org/grpc/examples/helloworld ``` -gRPC services are defined in a `.proto` file, which is used to generate a corresponding `.pb.go` file. The `.pb.go` file is generated by compiling the `.proto` file using the protocol compiler: `protoc`. +gRPC services are defined in a `.proto` file, which is used to generate a +corresponding `.pb.go` file. The `.pb.go` file is generated by compiling the +`.proto` file using the protocol compiler: `protoc`. -For the purpose of this example, the `helloworld.pb.go` file has already been generated (by compiling `helloworld.proto`), and can be found in this directory: `$GOPATH/src/google.golang.org/grpc/examples/helloworld/helloworld` +For the purpose of this example, the `helloworld.pb.go` file has already been +generated (by compiling `helloworld.proto`), and can be found in this directory: +`$GOPATH/src/google.golang.org/grpc/examples/helloworld/helloworld` This `helloworld.pb.go` file contains: - * Generated client and server code. - * Code for populating, serializing, and retrieving our `HelloRequest` and `HelloReply` message types. +- Generated client and server code. +- Code for populating, serializing, and retrieving our `HelloRequest` and + `HelloReply` message types. ### Try it! @@ -115,10 +116,12 @@ message HelloReply { } ``` -Let's update this so that the `Greeter` service has two methods. Make sure you are in the same examples dir as above (`$GOPATH/src/google.golang.org/grpc/examples/helloworld`) +Let's update this so that the `Greeter` service has two methods. Make sure you +are in the same examples dir as above +(`$GOPATH/src/google.golang.org/grpc/examples/helloworld`). -Edit `helloworld/helloworld.proto` and update it with a new `SayHelloAgain` method, with the same request and response -types: +Edit `helloworld/helloworld.proto` and update it with a new `SayHelloAgain` +method, with the same request and response types: ```protobuf // The greeting service definition. @@ -143,7 +146,8 @@ message HelloReply { ### Generate gRPC code Next we need to update the gRPC code used by our application to use the new -service definition. From the same examples dir as above (`$GOPATH/src/google.golang.org/grpc/examples/helloworld`) +service definition. From the same examples dir as above +(`$GOPATH/src/google.golang.org/grpc/examples/helloworld`): ```sh $ protoc -I helloworld/ helloworld/helloworld.proto --go_out=plugins=grpc:helloworld @@ -180,30 +184,29 @@ log.Printf("Greeting: %s", r.GetMessage()) #### Run! -Run the server + 1. Run the server: -```sh -$ go run greeter_server/main.go -``` + ```sh + $ go run greeter_server/main.go + ``` -On a different terminal, run the client + 2. On a different terminal, run the client: -```sh -$ go run greeter_client/main.go -``` + ```sh + $ go run greeter_client/main.go + ``` -You should see the updated output: + You'll see the following output: -```sh -$ go run greeter_client/main.go -Greeting: Hello world -Greeting: Hello again world -``` + ```sh + Greeting: Hello world + Greeting: Hello again world + ``` ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) -- Work through a more detailed tutorial in [gRPC Basics: Go](/docs/tutorials/basic/go/) + and [gRPC Concepts](/docs/guides/concepts/). +- Work through a more detailed tutorial in [gRPC Basics: Go](/docs/tutorials/basic/go/). - Explore the gRPC Go core API in its [reference - documentation](https://godoc.org/google.golang.org/grpc) + documentation](https://godoc.org/google.golang.org/grpc). diff --git a/content/docs/quickstart/java.md b/content/docs/quickstart/java.md index 70caab5..f405070 100644 --- a/content/docs/quickstart/java.md +++ b/content/docs/quickstart/java.md @@ -7,17 +7,15 @@ description: This guide gets you started with gRPC in Java with a simple working
-### Before you begin +### Prerequisites -#### Prerequisites - -* JDK: version 7 or higher +- JDK version 7 or higher ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh @@ -37,13 +35,13 @@ From the `examples` directory: $ ./gradlew installDist ``` - 2. Run the server + 2. Run the server: ```sh $ ./build/install/examples/bin/hello-world-server ``` - 3. In another terminal, run the client + 3. From another terminal, run the client: ```sh $ ./build/install/examples/bin/hello-world-client @@ -103,7 +101,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Update and run the application @@ -172,19 +170,19 @@ public void greet(String name) { Just like we did before, from the `examples` directory: - 1. Compile the client and server + 1. Compile the client and server: ```sh $ ./gradlew installDist ``` - 2. Run the server + 2. Run the server: ```sh $ ./build/install/examples/bin/hello-world-server ``` - 3. In another terminal, run the client + 3. From another terminal, run the client: ```sh $ ./build/install/examples/bin/hello-world-client @@ -197,4 +195,3 @@ Just like we did before, from the `examples` directory: - Work through a more detailed tutorial in [gRPC Basics: Java](/docs/tutorials/basic/java/). - Explore the gRPC Java core API in its [reference documentation](/grpc-java/javadoc/). - diff --git a/content/docs/quickstart/node.md b/content/docs/quickstart/node.md index 108cc46..6b4788b 100644 --- a/content/docs/quickstart/node.md +++ b/content/docs/quickstart/node.md @@ -7,25 +7,23 @@ description: This guide gets you started with gRPC in Node with a simple working
-### Before you begin +### Prerequisites -#### Prerequisites - - * `node`: version 4.0.0 or higher +- Node version 4.0.0 or higher ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh -$ # Clone the repository to get the example code +# Clone the repository to get the example code $ git clone -b {{< param grpc_release_tag >}} https://github.com/grpc/grpc -$ # Navigate to the dynamic codegen "hello, world" Node example: +# Navigate to the dynamic codegen "hello, world" Node example: $ cd grpc/examples/node/dynamic_codegen -$ # Install the example's dependencies +# Install the example's dependencies $ npm install ``` @@ -33,13 +31,13 @@ $ npm install From the `examples/node/dynamic_codegen` directory: - 1. Run the server + 1. Run the server: ```sh $ node greeter_server.js ``` - 2. In another terminal, run the client + 2. From another terminal, run the client: ```sh $ node greeter_client.js @@ -100,7 +98,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Update and run the application @@ -128,7 +126,6 @@ function main() { server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure()); server.start(); } -... ``` #### Update the client @@ -152,13 +149,13 @@ function main() { Just like we did before, from the `examples/node/dynamic_codegen` directory: - 1. Run the server + 1. Run the server: ```sh $ node greeter_server.js ``` - 2. In another terminal, run the client + 2. From another terminal, run the client: ```sh $ node greeter_client.js @@ -167,8 +164,8 @@ Just like we did before, from the `examples/node/dynamic_codegen` directory: ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) - - Work through a more detailed tutorial in [gRPC Basics: Node](/docs/tutorials/basic/node/) + and [gRPC Concepts](/docs/guides/concepts/). + - Work through a more detailed tutorial in [gRPC Basics: Node](/docs/tutorials/basic/node/). - Explore the gRPC Node core API in its [reference - documentation](/grpc/node/) + documentation](/grpc/node/). - We do have more than one grpc implementation for nodejs. [Learn about the pros and cons of each here](https://github.com/grpc/grpc-node/blob/master/PACKAGE-COMPARISON.md). diff --git a/content/docs/quickstart/objective-c.md b/content/docs/quickstart/objective-c.md index 469a626..fccff04 100644 --- a/content/docs/quickstart/objective-c.md +++ b/content/docs/quickstart/objective-c.md @@ -9,43 +9,42 @@ description: This guide gets you started with gRPC on the iOS platform in Object ### Before you begin -#### System requirement -The minimum deployment iOS version for gRPC is 7.0. +#### System requirements -OS X El Capitan (version 10.11) or above is required to build and run this -Quickstart. +- macOS version 10.11 (El Capitan) or higher +- iOS version 7.0 or higher #### Prerequisites -* `CocoaPods`: version 1.0 or higher +- CocoaPods version 1.0 or higher - * Check status and version of CocoaPods on your system with command `pod - --version`. - * If CocoaPods is not installed, follow the install instructions on CocoaPods - [website](https://cocoapods.org). + Check the status and version of CocoaPods on your system: -* `Xcode`: version 7.2 or higher + ```sh + $ pod --version + ``` - * Check your Xcode version by running Xcode from Lauchpad, then select - "Xcode->About Xcode" in the menu. - * Make sure the command line developer tools are installed: - ```sh - [sudo] xcode-select --install - ``` + If CocoaPods is not installed, follow the [CocoaPods install + instructions](https://cocoapods.org). -* `Homebrew` - * Check status and version of Homebrew on your system with command `brew - --version`. - * If Homebrew is not installed, install with: - ```sh - /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" - ``` +- Xcode version 7.2 or higher -* `autoconf`, `automake`, `libtool`, `pkg-config` - * Install with Homebrew - ```sh - brew install autoconf automake libtool pkg-config - ``` + Check your Xcode version by running Xcode from Lauchpad, then select + **Xcode > About Xcode** in the menu. + + Make sure the command line developer tools are installed: + + ```sh + $ xcode-select --install + ``` + +- [Homebrew](https://brew.sh/) + +- `autoconf`, `automake`, `libtool`, `pkg-config` + + ```sh + $ brew install autoconf automake libtool pkg-config + ``` ### Download the example @@ -58,6 +57,7 @@ $ git clone --recursive -b {{< param grpc_release_tag >}} https://github.com/grp ``` ### Install gRPC plugins and libraries + ```sh $ cd grpc $ make @@ -65,15 +65,16 @@ $ [sudo] make install ``` ### Install protoc compiler + ```sh $ brew tap grpc/grpc $ brew install protobuf ``` -### Run the server +### Run the server: For this sample app, we need a gRPC server running on the local machine. gRPC -Objective-C API supports creating gRPC clients but not gRPC servers. Therefore +Objective-C API supports creating gRPC clients but not gRPC servers. Therefore instead we build and run the C++ server in the same repository: ```sh @@ -82,7 +83,7 @@ $ make $ ./greeter_server & ``` -### Run the client +### Run the client: #### Generate client libraries and dependencies @@ -120,13 +121,13 @@ Congratulations! You've just run a client-server application with gRPC. Now let's look at how to update the application with an extra method on the server for the client to call. Our gRPC service is defined using Protocol Buffers; you can find out lots more about how to define a service in a `.proto` -file in Protocol Buffers -[website](https://developers.google.com/protocol-buffers/). For now all you +file in Protocol Buffers +[website](https://developers.google.com/protocol-buffers/). For now all you need to know is that both the server and the client "stub" have a `SayHello` RPC method that takes a `HelloRequest` parameter from the client and returns a `HelloResponse` from the server, and that this method is defined like this: -```c +```protobuf // The greeting service definition. service Greeter { // Sends a greeting @@ -148,7 +149,7 @@ Let's update this so that the `Greeter` service has two methods. Edit `examples/protos/helloworld.proto` and update it with a new `SayHelloAgain` method, with the same request and response types: -```c +```protobuf // The greeting service definition. service Greeter { // Sends a greeting @@ -168,7 +169,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Update the client and server @@ -258,59 +259,63 @@ above. Open the client Xcode project in Xcode: ```sh $ open HelloWorld.xcworkspace ``` -and run the client app. If you look at the console messages, you should see two RPC calls, + +and run the client app. If you look at the console messages, You'll see two RPC calls, one to SayHello and one to SayHelloAgain. ### Troubleshooting -**When installing CocoaPods, error prompt `activesupport requires Ruby version >= 2.2.2.`** +When installing CocoaPods, error `activesupport requires Ruby version >= 2.2.2` -Install an older version of `activesupport`, then install CocoaPods: -```sh -[sudo] gem install activesupport -v 4.2.6 -[sudo] gem install cocoapods -``` -**When installing dependencies with CocoaPods, error prompt `Unable to find a specification for !ProtoCompiler-gRPCPlugin`** +: Install an older version of `activesupport`, then install CocoaPods: -Update the local clone of spec repo by running `pod repo update` + ```sh + $ [sudo] gem install activesupport -v 4.2.6 + $ [sudo] gem install cocoapods + ``` -**Compiler error when compiling `objective_c_plugin.cc`** +When installing dependencies with CocoaPods, error `Unable to find a specification for !ProtoCompiler-gRPCPlugin` -Removing `protobuf` package with Homebrew before building gRPC may solve -this problem. We are working on a more elegant fix. +: Update the local clone of spec repo by running `pod repo update` -**When building HellowWorld, error prompt `ld: unknown option: --no-as-needed`** +Compiler error when compiling `objective_c_plugin.cc` -This problem is due to linker `ld` in Apple LLVM not supporting the ---no-as-needed option. We are working on a fix right now and will merge the fix -very soon. +: Removing `protobuf` package with Homebrew before building gRPC may solve this + problem. We are working on a more elegant fix. -**When building grpc, error prompt `cannot find install-sh install.sh or shtool`** +When building HellowWorld, error `ld: unknown option: --no-as-needed` -Remove the gRPC directory, clone a new one and try again. It is likely that some -auto generated files are corrupt; remove and rebuild may solve the problem. +: This problem is due to linker `ld` in Apple LLVM not supporting the + `--no-as-needed` option. We are working on a fix right now and will merge the + fix very soon. -**When building grpc, error prompt `Can't exec "aclocal"`** +When building grpc, error `cannot find install-sh install.sh or shtool` -The package `automake` is missing. Install `automake` should solve this problem. +: Remove the gRPC directory, clone a new one and try again. It is likely that + some auto generated files are corrupt; remove and rebuild may solve the + problem. -**When building grpc, error prompt `possibly undefined macro: AC_PROG_LIBTOOL`** +When building grpc, error `Can't exec "aclocal"` -The package `libtool` is missing. Install `libtool` should solve this problem. +: The package `automake` is missing. Install `automake` should solve this problem. -**When building grpc, error prompt `cannot find install-sh, install.sh, or shtool`** +When building grpc, error `possibly undefined macro: AC_PROG_LIBTOOL` -Some of the auto generated files are corrupt. Remove the entire gRPC directory, -clone from GitHub, and build again. +: The package `libtool` is missing. Install `libtool` should solve this problem. -**Cannot find `protoc` when building HelloWorld** +When building grpc, error `cannot find install-sh, install.sh, or shtool` -Run `brew install protobuf` to get `protoc` compiler. +: Some of the auto generated files are corrupt. Remove the entire gRPC + directory, clone from GitHub, and build again. + +Cannot find `protoc` when building HelloWorld + +: Run `brew install protobuf` to get the `protoc` compiler. ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) -- Work through a more detailed tutorial in [gRPC Basics: Objective-C](/docs/tutorials/basic/objective-c/) + and [gRPC Concepts](/docs/guides/concepts/). +- Work through a more detailed tutorial in [gRPC Basics: Objective-C](/docs/tutorials/basic/objective-c/). - Explore the Objective-C core API in its [reference - documentation](http://cocoadocs.org/docsets/gRPC/) + documentation](http://cocoadocs.org/docsets/gRPC/). diff --git a/content/docs/quickstart/php.md b/content/docs/quickstart/php.md index d705313..45a9f84 100644 --- a/content/docs/quickstart/php.md +++ b/content/docs/quickstart/php.md @@ -9,10 +9,10 @@ description: This guide gets you started with gRPC in PHP with a simple working ### Prerequisites -* `php` 5.5 or above, 7.0 or above -* `pecl` -* `composer` -* `phpunit` (optional) +- PHP 5.5 or higher, 7.0 or higher +- PECL +- Composer +- PHPUnit (optional) **Install PHP and PECL on Ubuntu/Debian:** @@ -65,9 +65,10 @@ $ sudo mv phpunit-old.phar /usr/bin/phpunit ### Install the gRPC PHP extension -There are two ways to install gRPC PHP extension. -* `pecl` -* `build from source` +There are two ways to install gRPC PHP extension: + +- `pecl` +- `build from source` #### Using PECL @@ -81,7 +82,7 @@ or specific version sudo pecl install grpc-1.7.0 ``` -Note: for users on CentOS/RHEL 6, unfortunately this step won’t work. +Note: for users on CentOS/RHEL 6, unfortunately this step won’t work. Please follow the instructions below to compile the PECL extension from source. ##### Install on Windows @@ -118,16 +119,16 @@ $ make $ sudo make install ``` -This will compile and install the gRPC PHP extension into the -standard PHP extension directory. You should be able to run +This will compile and install the gRPC PHP extension into the +standard PHP extension directory. You should be able to run the [unit tests](#unit-tests), with the PHP extension installed. #### Update php.ini -After installing the gRPC extension, make sure you add this line -to your `php.ini` file, (e.g. `/etc/php5/cli/php.ini`, -`/etc/php5/apache2/php.ini`, or `/usr/local/etc/php/5.6/php.ini`), +After installing the gRPC extension, make sure you add this line +to your `php.ini` file, (e.g. `/etc/php5/cli/php.ini`, +`/etc/php5/apache2/php.ini`, or `/usr/local/etc/php/5.6/php.ini`), depending on where your PHP installation is. ```sh @@ -144,43 +145,43 @@ You need to add this to your project's `composer.json` file. } ``` -To run tests with generated stub code from `.proto` files, you will also +To run tests with generated stub code from `.proto` files, you will also need the `composer` and `protoc` binaries. You can find out how to get these below. ### Install other prerequisites for both Mac OS X and Linux -* `protoc: protobuf compiler` -* `protobuf.so: protobuf runtime library` -* `grpc_php_plugin: Generates PHP gRPC service interface out of Protobuf IDL` +- `protoc: protobuf compiler` +- `protobuf.so: protobuf runtime library` +- `grpc_php_plugin: Generates PHP gRPC service interface out of Protobuf IDL` #### Install Protobuf compiler If you don't have it already, you need to install the protobuf compiler `protoc`, version 3.4.0+ (the newer the better) for the current gRPC version. -If you installed already, make sure the protobuf version is compatible with the +If you installed already, make sure the protobuf version is compatible with the grpc version you installed. If you build grpc.so from source, you can check the version of grpc inside package.xml file. The compatibility between the grpc and protobuf version is listed as table below: grpc | protobuf ---- | --- +--- | --- v1.0.0 | 3.0.0(GA) v1.0.1 | 3.0.2 -v1.1.0 | 3.1.0 -v1.2.0 | 3.2.0 -v1.2.0 | 3.2.0 -v1.3.4 | 3.3.0 +v1.1.0 | 3.1.0 +v1.2.0 | 3.2.0 +v1.2.0 | 3.2.0 +v1.3.4 | 3.3.0 v1.3.5 | 3.2.0 -v1.4.0 | 3.3.0 +v1.4.0 | 3.3.0 v1.6.0 | 3.4.0 If `protoc` hasn't been installed, you can download the `protoc` binaries from [the protocol buffers GitHub repository](https://github.com/google/protobuf/releases). -Then unzip this file and Update the environment variable `PATH` to include the path to +Then unzip this file and Update the environment variable `PATH` to include the path to the protoc binary file./protobuf/releases). -Then unzip this file and Update the environment variable `PATH` to include the path to +Then unzip this file and Update the environment variable `PATH` to include the path to the protoc binary file. If you really must compile `protoc` from source, you can run the following @@ -196,11 +197,11 @@ $ sudo make install #### Protobuf Runtime library There are two protobuf runtime libraries to choose from. They are identical -in terms of APIs offered. The C implementation provides better performance, -while the native implementation is easier to install. Make sure the installed +in terms of APIs offered. The C implementation provides better performance, +while the native implementation is easier to install. Make sure the installed protobuf version works with grpc version. -##### 1. C implementation (for better performance) +##### C implementation (for better performance) ``` sh $ sudo pecl install protobuf @@ -211,16 +212,16 @@ or specific version $ sudo pecl install protobuf-3.4.0 ``` -After protobuf extension is installed, Update php.ini by adding this line -to your `php.ini` file, (e.g. `/etc/php5/cli/php.ini`, -`/etc/php5/apache2/php.ini`, or `/usr/local/etc/php/5.6/php.ini`), +After protobuf extension is installed, Update php.ini by adding this line +to your `php.ini` file, (e.g. `/etc/php5/cli/php.ini`, +`/etc/php5/apache2/php.ini`, or `/usr/local/etc/php/5.6/php.ini`), depending on where your PHP installation is. ```sh extension=protobuf.so ``` -##### 2. PHP implementation (for easier installation) +##### PHP implementation (for easier installation) Add this to your `composer.json` file: @@ -250,14 +251,14 @@ $ make grpc_php_plugin ``` Plugin may use the new feature of the new protobuf version, thus please also -make sure that the protobuf version installed is compatible with the grpc version +make sure that the protobuf version installed is compatible with the grpc version you build this plugin. ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): Note that currently you can only create clients in PHP for gRPC services - @@ -265,11 +266,11 @@ you can find out how to create gRPC servers in our other tutorials, e.g. [Node.js](/docs/tutorials/basic/node/). ```sh -$ # Clone the repository to get the example code: +# Clone the repository to get the example code: $ git clone -b {{< param grpc_release_tag >}} https://github.com/grpc/grpc -$ # Build grpc_php_plugin to generate proto files if not build before +# Build grpc_php_plugin to generate proto files if not build before $ cd grpc && git submodule update --init && make grpc_php_plugin -$ # Navigate to the "hello, world" PHP example: +# Navigate to the "hello, world" PHP example: $ cd examples/php $ ./greeter_proto_gen.sh $ composer install @@ -279,21 +280,20 @@ $ composer install From the `examples/node` directory: -1. Run the server + 1. Run the server: - ```sh - $ npm install - $ cd dynamic_codegen - $ node greeter_server.js - ``` + ```sh + $ npm install + $ cd dynamic_codegen + $ node greeter_server.js + ``` -In another terminal, from the `examples/php` directory: + 2. From another terminal, from the `examples/php` directory, + run the client: -1. Run the client - - ```sh - $ ./run_greeter_client.sh - ``` + ```sh + $ ./run_greeter_client.sh + ``` Congratulations! You've just run a client-server application with gRPC. @@ -308,7 +308,7 @@ server and the client "stub" have a `SayHello` RPC method that takes a the server, and that this method is defined like this: -```php +```protobuf // The greeting service definition. service Greeter { // Sends a greeting @@ -330,7 +330,7 @@ Let's update this so that the `Greeter` service has two methods. Edit `examples/protos/helloworld.proto` and update it with a new `SayHelloAgain` method, with the same request and response types: -```php +```protobuf // The greeting service definition. service Greeter { // Sends a greeting @@ -350,7 +350,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Generate gRPC code @@ -410,36 +410,35 @@ function main() { In the same directory, open `greeter_client.php`. Call the new method like this: ```php - $request = new Helloworld\HelloRequest(); - $request->setName($name); - list($reply, $status) = $client->SayHello($request)->wait(); - $message = $reply->getMessage(); - list($reply, $status) = $client->SayHelloAgain($request)->wait(); - $message = $reply->getMessage(); +$request = new Helloworld\HelloRequest(); +$request->setName($name); +list($reply, $status) = $client->SayHello($request)->wait(); +$message = $reply->getMessage(); +list($reply, $status) = $client->SayHelloAgain($request)->wait(); +$message = $reply->getMessage(); ``` #### Run! Just like we did before, from the `examples/node/dynamic_codegen` directory: -1. Run the server + 1. Run the server: - ```sh - $ node greeter_server.js - ``` + ```sh + $ node greeter_server.js + ``` -In another terminal, from the `examples/php` directory: + 2. From another terminal, from the `examples/php` directory, + run the client: -2. Run the client - - ```sh - $ ./run_greeter_client.sh - ``` + ```sh + $ ./run_greeter_client.sh + ``` ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) -- Work through a more detailed tutorial in [gRPC Basics: PHP](/docs/tutorials/basic/php/) + and [gRPC Concepts](/docs/guides/concepts/). +- Work through a more detailed tutorial in [gRPC Basics: PHP](/docs/tutorials/basic/php/). - Explore the gRPC PHP core API in its [reference - documentation](/grpc/php/namespace-Grpc.html) + documentation](/grpc/php/namespace-Grpc.html). diff --git a/content/docs/quickstart/python.md b/content/docs/quickstart/python.md index 1231bc8..6591cd9 100644 --- a/content/docs/quickstart/python.md +++ b/content/docs/quickstart/python.md @@ -7,13 +7,12 @@ description: This guide gets you started with gRPC in Python with a simple worki
-### Before you begin +### Prerequisites -#### Prerequisites +- Python 2.7, or Python 3.4 or higher +- `pip` version 9.0.1 or higher -gRPC Python is supported for use with Python 2.7 or Python 3.4 or higher. - -Ensure you have `pip` version 9.0.1 or higher: +If necessary, upgrade your version of `pip`: ```sh $ python -m pip install --upgrade pip @@ -29,7 +28,7 @@ $ source venv/bin/activate $ python -m pip install --upgrade pip ``` -#### Install gRPC +#### gRPC Install gRPC: @@ -55,14 +54,14 @@ You can work around this using: $ python -m pip install grpcio --ignore-installed ``` -#### Install gRPC tools +#### gRPC tools Python's gRPC tools include the protocol buffer compiler `protoc` and the special plugin for generating server and client code from `.proto` service -definitions. For the first part of our quickstart example, we've already +definitions. For the first part of our quick-start example, we've already generated the server and client stubs from [helloworld.proto](https://github.com/grpc/grpc/tree/{{< param grpc_release_tag >}}/examples/protos/helloworld.proto), -but you'll need the tools for the rest of our quickstart, as well as later +but you'll need the tools for the rest of our quick start, as well as later tutorials and your own projects. To install gRPC tools, run: @@ -73,15 +72,15 @@ $ python -m pip install grpcio-tools ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh -$ # Clone the repository to get the example code: +# Clone the repository to get the example code: $ git clone -b {{< param grpc_release_tag >}} https://github.com/grpc/grpc -$ # Navigate to the "hello, world" Python example: +# Navigate to the "hello, world" Python example: $ cd grpc/examples/python/helloworld ``` @@ -89,13 +88,13 @@ $ cd grpc/examples/python/helloworld From the `examples/python/helloworld` directory: -1. Run the server +1. Run the server: ```sh $ python greeter_server.py ``` -2. In another terminal, run the client +2. From another terminal, run the client: ```sh $ python greeter_client.py @@ -156,12 +155,12 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Generate gRPC code Next we need to update the gRPC code used by our application to use the new -service definition. +service definition. From the `examples/python/helloworld` directory, run: @@ -212,22 +211,22 @@ def run(): Just like we did before, from the `examples/python/helloworld` directory: -1. Run the server + 1. Run the server: - ```sh - $ python greeter_server.py - ``` + ```sh + $ python greeter_server.py + ``` -2. In another terminal, run the client + 2. From another terminal, run the client: - ```sh - $ python greeter_client.py - ``` + ```sh + $ python greeter_client.py + ``` ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) -- Work through a more detailed tutorial in [gRPC Basics: Python](/docs/tutorials/basic/python/) + and [gRPC Concepts](/docs/guides/concepts/). +- Work through a more detailed tutorial in [gRPC Basics: Python](/docs/tutorials/basic/python/). - Explore the gRPC Python core API in its [reference - documentation](/grpc/python/) \ No newline at end of file + documentation](/grpc/python/). diff --git a/content/docs/quickstart/ruby.md b/content/docs/quickstart/ruby.md index 6532096..7516193 100644 --- a/content/docs/quickstart/ruby.md +++ b/content/docs/quickstart/ruby.md @@ -7,45 +7,45 @@ description: This guide gets you started with gRPC in Ruby with a simple working
-### Before you begin +### Prerequisites -#### Prerequisites +- Ruby version 2 or higher - * `ruby`: version 2 or higher +#### gRPC -#### Install gRPC +To install gRPC, run the following command: -``` +```sh $ gem install grpc ``` -#### Install gRPC tools +#### gRPC tools Ruby's gRPC tools include the protocol buffer compiler `protoc` and the special plugin for generating server and client code from the `.proto` service -definitions. For the first part of our quickstart example, we've already +definitions. For the first part of our quick-start example, we've already generated the server and client stubs from [helloworld.proto](https://github.com/grpc/grpc/tree/{{< param grpc_release_tag >}}/examples/protos/helloworld.proto), -but you'll need the tools for the rest of our quickstart, as well as later +but you'll need the tools for the rest of our quick start, as well as later tutorials and your own projects. -To install gRPC tools, run: +To install gRPC tools, run the following command: ```sh -gem install grpc-tools +$ gem install grpc-tools ``` ### Download the example -You'll need a local copy of the example code to work through this quickstart. +You'll need a local copy of the example code to work through this quick start. Download the example code from our GitHub repository (the following command -clones the entire repository, but you just need the examples for this quickstart +clones the entire repository, but you just need the examples for this quick start and other tutorials): ```sh -$ # Clone the repository to get the example code: +# Clone the repository to get the example code: $ git clone -b {{< param grpc_release_tag >}} https://github.com/grpc/grpc -$ # Navigate to the "hello, world" Ruby example: +# Navigate to the "hello, world" Ruby example: $ cd grpc/examples/ruby ``` @@ -53,17 +53,17 @@ $ cd grpc/examples/ruby From the `examples/ruby` directory: -1. Run the server + 1. Run the server: - ```sh - $ ruby greeter_server.rb - ``` + ```sh + $ ruby greeter_server.rb + ``` -2. In another terminal, run the client + 2. From another terminal, run the client: - ```sh - $ ruby greeter_client.rb - ``` + ```sh + $ ruby greeter_client.rb + ``` Congratulations! You've just run a client-server application with gRPC. @@ -120,7 +120,7 @@ message HelloReply { } ``` -(Don't forget to save the file!) +Remember to save the file! ### Generate gRPC code @@ -149,7 +149,6 @@ class GreeterServer < Helloworld::Greeter::Service Helloworld::HelloReply.new(message: "Hello again, #{hello_req.name}") end end -... ``` #### Update the client @@ -171,22 +170,22 @@ end Just like we did before, from the `examples/ruby` directory: -1. Run the server + 1. Run the server: - ```sh - $ ruby greeter_server.rb - ``` + ```sh + $ ruby greeter_server.rb + ``` -2. In another terminal, run the client + 2. From another terminal, run the client: - ```sh - $ ruby greeter_client.rb - ``` + ```sh + $ ruby greeter_client.rb + ``` ### What's next - Read a full explanation of how gRPC works in [What is gRPC?](/docs/guides/) - and [gRPC Concepts](/docs/guides/concepts/) - - Work through a more detailed tutorial in [gRPC Basics: Ruby](/docs/tutorials/basic/ruby/) + and [gRPC Concepts](/docs/guides/concepts/). + - Work through a more detailed tutorial in [gRPC Basics: Ruby](/docs/tutorials/basic/ruby/). - Explore the gRPC Ruby core API in its [reference - documentation](http://www.rubydoc.info/gems/grpc) \ No newline at end of file + documentation](http://www.rubydoc.info/gems/grpc). diff --git a/content/docs/quickstart/web.md b/content/docs/quickstart/web.md index c3ba7fd..b52f11a 100644 --- a/content/docs/quickstart/web.md +++ b/content/docs/quickstart/web.md @@ -9,13 +9,14 @@ description: This guide gets you started with gRPC-Web with a simple working exa ### Prerequisites -* `docker` and `docker-compose` +- `docker` +- `docker-compose` This demo requires Docker Compose file [version 3](https://docs.docker.com/compose/compose-file/). Please refer to [Docker website](https://docs.docker.com/compose/install/#install-compose) on how to install Docker. -### Run an Echo example from the browser! +### Run an Echo example from your browser! ```sh $ git clone https://github.com/grpc/grpc-web @@ -24,35 +25,30 @@ $ docker-compose pull $ docker-compose up -d node-server envoy commonjs-client ``` -Open a browser tab, and go to: - -```sh -http://localhost:8081/echotest.html -``` +From your browser visit +[localhost:8081/echotest.html](http://localhost:8081/echotest.html). To shutdown, run `docker-compose down`. -### What is Happening? +### What is happening? In this demo, there are three key components: - 1. `node-server`: This is a standard gRPC Server, implemented in Node. - This server listens at port `:9090` and implements the service's business - logic. - + 1. `node-server`: This is a standard gRPC Server, implemented in Node. This + server listens at port `:9090` and implements the service's business logic. + 2. `envoy`: This is the Envoy proxy. It listens at `:8080` and forwards the - browser's gRPC-Web requests to port `:9090`. This is done via a config file - `envoy.yaml`. - - 3. `commonjs-client`: This component generates the client stub class using - the `protoc-gen-grpc-web` protoc plugin, compiles all the JS dependencies - using `webpack`, and hosts the static content `echotest.html` and - `dist/main.js` using a simple web server at port `:8081`. Once the user - interacts with the webpage, it sends a gRPC-Web request to the Envoy proxy - endpoint at `:8080`. + browser's gRPC-Web requests to port `:9090`. This is done via a config file + `envoy.yaml`. + + 3. `commonjs-client`: This component generates the client stub class using the + `protoc-gen-grpc-web` protoc plugin, compiles all the JS dependencies using + `webpack`, and hosts the static content `echotest.html` and `dist/main.js` + using a simple web server at port `:8081`. Once the user interacts with the + webpage, it sends a gRPC-Web request to the Envoy proxy endpoint at `:8080`. ### What's next -- Work through a more detailed tutorial in [gRPC Basics: Web](/docs/tutorials/basic/web/) +- Work through a more detailed tutorial in [gRPC Basics: Web](/docs/tutorials/basic/web/). diff --git a/content/docs/tutorials/auth/oauth2-objective-c.md b/content/docs/tutorials/auth/oauth2-objective-c.md index 0fce88d..2afc718 100644 --- a/content/docs/tutorials/auth/oauth2-objective-c.md +++ b/content/docs/tutorials/auth/oauth2-objective-c.md @@ -175,6 +175,7 @@ To use this approach, first create a class in your project that conforms to ``` When creating an RPC object, pass an instance of this class to call option `authTokenProvider`: + ```objective-c GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init]; options.authTokenProvider = [[TokenProvider alloc] init]; diff --git a/content/docs/tutorials/basic/android.md b/content/docs/tutorials/basic/android.md index 6706e42..0042da6 100644 --- a/content/docs/tutorials/basic/android.md +++ b/content/docs/tutorials/basic/android.md @@ -63,40 +63,58 @@ service RouteGuide { Then we define `rpc` methods inside our service definition, specifying their request and response types. gRPC lets you define four kinds of service method, all of which are used in the `RouteGuide` service: -- A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. +- A *simple RPC* where the client sends a request to the server using the stub + and waits for a response to come back, just like a normal function call. -```proto -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```proto + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` -- A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the returned stream until there are no more messages. As you can see in our example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. +- A *server-side streaming RPC* where the client sends a request to the server + and gets a stream to read a sequence of messages back. The client reads from + the returned stream until there are no more messages. As you can see in our + example, you specify a server-side streaming method by placing the `stream` + keyword before the *response* type. -```proto -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```proto + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` -- A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has finished writing the messages, it waits for the server to read them all and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. +- A *client-side streaming RPC* where the client writes a sequence of messages + and sends them to the server, again using a provided stream. Once the client + has finished writing the messages, it waits for the server to read them all + and return its response. You specify a client-side streaming method by placing + the `stream` keyword before the *request* type. -```proto -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```proto + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` -- A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients and servers can read and write in whatever order they like: for example, the server could wait to receive all the client messages before writing its responses, or it could alternately read a message then write a message, or some other combination of reads and writes. The order of messages in each stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. +- A *bidirectional streaming RPC* where both sides send a sequence of messages + using a read-write stream. The two streams operate independently, so clients + and servers can read and write in whatever order they like: for example, the + server could wait to receive all the client messages before writing its + responses, or it could alternately read a message then write a message, or + some other combination of reads and writes. The order of messages in each + stream is preserved. You specify this type of method by placing the `stream` + keyword before both the request and the response. -```proto -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```proto + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: +Our `.proto` file also contains protocol buffer message type definitions for all +the request and response types used in our service methods - for example, here's +the `Point` message type: ```proto // Points are represented as latitude-longitude pairs in the E7 representation @@ -109,7 +127,6 @@ message Point { } ``` - ### Generating client code Next we need to generate the gRPC client interfaces from our .proto diff --git a/content/docs/tutorials/basic/cpp.md b/content/docs/tutorials/basic/cpp.md index 54e7285..0568ee7 100644 --- a/content/docs/tutorials/basic/cpp.md +++ b/content/docs/tutorials/basic/cpp.md @@ -74,7 +74,7 @@ You can see the complete .proto file in To define a service, you specify a named `service` in your .proto file: -```c +```protobuf service RouteGuide { ... } @@ -87,10 +87,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```c -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -98,13 +98,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```c -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -112,11 +112,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```c -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -127,17 +127,17 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```c -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: -```c +```protobuf // Points are represented as latitude-longitude pairs in the E7 representation // (degrees multiplied by 10**7 and rounded to the nearest integer). // Latitudes should be in the range +/- 90 degrees and longitude should be in @@ -148,7 +148,6 @@ message Point { } ``` - ### Generating client and server code Next we need to generate the gRPC client and server interfaces from our .proto @@ -520,17 +519,19 @@ independently. ### Try it out! -Build client and server: +Build the client and server: ```sh $ make ``` -Run the server, which will listen on port 50051: + +Run the server: ```sh $ ./route_guide_server ``` -Run the client (in a different terminal): + +From a different terminal, run the client: ```sh $ ./route_guide_client diff --git a/content/docs/tutorials/basic/csharp.md b/content/docs/tutorials/basic/csharp.md index d34039f..a509fe3 100644 --- a/content/docs/tutorials/basic/csharp.md +++ b/content/docs/tutorials/basic/csharp.md @@ -17,7 +17,7 @@ It assumes that you have read the [Overview](/docs/) and are familiar with [protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). Note that the example in this tutorial uses the proto3 version of the protocol buffers language: you can find out more in the -[proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and +[proto3 language guide](https://developers.google.com/protocol-buffers/docs/proto3) and [C# generated code reference](https://developers.google.com/protocol-buffers/docs/reference/csharp-generated).
@@ -61,7 +61,7 @@ instructions](https://github.com/grpc/grpc/tree/ Our first step (as you'll know from the [Overview](/docs/)) is to define the gRPC *service* and the method *request* and *response* types using -[protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). +[protocol buffers](https://developers.google.com/protocol-buffers/docs/overview). You can see the complete .proto file in [`examples/protos/route_guide.proto`](https://github.com/grpc/grpc/blob/ {{< param grpc_release_tag >}}/examples/protos/route_guide.proto). @@ -82,10 +82,10 @@ all of which are used in the `RouteGuide` service: object and waits for a response to come back, just like a normal function call. -```protobuf -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -93,13 +93,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```protobuf -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -107,11 +107,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```protobuf -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -122,13 +122,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```protobuf -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: @@ -480,28 +480,27 @@ using (var call = client.RouteChat()) ### Try it out! -#### Build the client and server: +Build the client and server: -##### Using Visual Studio (or Visual Studio For Mac) +Using Visual Studio (or Visual Studio For Mac) +: Open the solution `examples/csharp/RouteGuide/RouteGuide.sln` and select **Build**. -- Open the solution `examples/csharp/RouteGuide/RouteGuide.sln` and select **Build**. +Using `dotnet` command line tool -##### Using "dotnet" command line tool +: Run `dotnet build RouteGuide.sln` from the `examples/csharp/RouteGuide` + directory. For additional instructions on building the gRPC example with the + `dotnet` command line tool, see [Quick Start](../../quickstart/csharp.html). -- Run `dotnet build RouteGuide.sln` from the `examples/csharp/RouteGuide` directory. - See the [quickstart](../../quickstart/csharp.html) for additional instructions on building - the gRPC example with the `dotnet` command line tool. +Run the server: -Run the server, which will listen on port 50052: - -``` +```sh > cd RouteGuideServer/bin/Debug/netcoreapp2.1 > dotnet exec RouteGuideServer.dll ``` -Run the client (in a different terminal): +From a different terminal, run the client: -``` +```sh > cd RouteGuideClient/bin/Debug/netcoreapp2.1 > dotnet exec RouteGuideClient.dll ``` diff --git a/content/docs/tutorials/basic/dart.md b/content/docs/tutorials/basic/dart.md index 02d7413..5704cf5 100644 --- a/content/docs/tutorials/basic/dart.md +++ b/content/docs/tutorials/basic/dart.md @@ -56,7 +56,6 @@ $ cd grpc-dart/example/route_guide You also should have the relevant tools installed to generate the server and client interface code - if you don't already, follow the setup instructions in [the Dart quick start guide](/docs/quickstart/dart/). - ### Defining the service Our first step (as you'll know from the [Overview](/docs/)) is to @@ -80,10 +79,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```proto -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```proto + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -91,13 +90,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```proto -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```proto + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -105,11 +104,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```proto -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```proto + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -120,13 +119,15 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```proto -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```proto + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: +Our `.proto` file also contains protocol buffer message type definitions for all +the request and response types used in our service methods - for example, here's +the `Point` message type: ```proto // Points are represented as latitude-longitude pairs in the E7 representation @@ -146,7 +147,7 @@ service definition. We do this using the protocol buffer compiler `protoc` with a special Dart plugin. This is similar to what we did in the [quickstart guide](/docs/quickstart/) -From the `route_guide` example directory run : +From the `route_guide` example directory run: ```sh protoc -I protos/ protos/route_guide.proto --dart_out=grpc:lib/src/generated @@ -521,21 +522,25 @@ write in any order — the streams operate completely independently. ### Try it out! -Go to the `examples/route_guide` folder. +Work from the example directory: -First, make sure dependencies are downloaded: +```sh +$ cd examples/route_guide +``` + +Get packages: ```sh $ pub get ``` -To run the server, simply: +Run the server: ```sh $ dart bin/server.dart ``` -Likewise, to run the client: +From a different terminal, run the client: ```sh $ dart bin/client.dart diff --git a/content/docs/tutorials/basic/go.md b/content/docs/tutorials/basic/go.md index 65f553d..aecb71e 100644 --- a/content/docs/tutorials/basic/go.md +++ b/content/docs/tutorials/basic/go.md @@ -82,10 +82,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```proto -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```proto + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -93,13 +93,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```proto -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```proto + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -107,11 +107,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```proto -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```proto + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -122,13 +122,15 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```proto -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```proto + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: +Our `.proto` file also contains protocol buffer message type definitions for all +the request and response types used in our service methods - for example, here's +the `Point` message type: ```proto // Points are represented as latitude-longitude pairs in the E7 representation @@ -145,16 +147,18 @@ message Point { Next we need to generate the gRPC client and server interfaces from our .proto service definition. We do this using the protocol buffer compiler `protoc` with -a special gRPC Go plugin. +a special gRPC Go plugin. This is similar to what we did in the [quickstart guide](/docs/quickstart/go/) -From the `route_guide` example directory run : +From the `route_guide` example directory run: ```sh protoc -I routeguide/ routeguide/route_guide.proto --go_out=plugins=grpc:routeguide ``` -Running this command generates the following file in the `routeguide` directory under the `route_guide` example directory: +Running this command generates the following file in the `routeguide` directory +under the `route_guide` example directory: + - `route_guide.pb.go` This contains: @@ -573,14 +577,19 @@ any order — the streams operate completely independently. ### Try it out! -To compile and run the server, assuming you are in the folder -`$GOPATH/src/google.golang.org/grpc/examples/route_guide`, simply: +Work from the example directory: + +```sh +$ cd $GOPATH/src/google.golang.org/grpc/examples/route_guide +``` + +Run the server: ```sh $ go run server/server.go ``` -Likewise, to run the client: +From a different terminal, run the client: ```sh $ go run client/client.go diff --git a/content/docs/tutorials/basic/java.md b/content/docs/tutorials/basic/java.md index 5142788..9de9658 100644 --- a/content/docs/tutorials/basic/java.md +++ b/content/docs/tutorials/basic/java.md @@ -57,7 +57,6 @@ Then change your current directory to `grpc-java/examples`: $ cd grpc-java/examples ``` - ### Defining the service Our first step (as you'll know from the [Overview](/docs/)) is to @@ -96,10 +95,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```proto -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```proto + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -107,13 +106,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```proto -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```proto + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -121,11 +120,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```proto -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```proto + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -136,13 +135,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```proto -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```proto + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: @@ -157,7 +156,6 @@ message Point { } ``` - ### Generating client and server code Next we need to generate the gRPC client and server interfaces from our .proto @@ -181,7 +179,6 @@ The following classes are generated from our service definition: `RouteGuide` service. - *stub* classes that clients can use to talk to a `RouteGuide` server. - ### Creating the server diff --git a/content/docs/tutorials/basic/node.md b/content/docs/tutorials/basic/node.md index 309afd3..c8a8413 100644 --- a/content/docs/tutorials/basic/node.md +++ b/content/docs/tutorials/basic/node.md @@ -99,10 +99,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```protobuf -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -110,13 +110,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```protobuf -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -124,11 +124,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```protobuf -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -139,13 +139,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```protobuf -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: @@ -512,17 +512,19 @@ independently. ### Try it out! -Build client and server: +Build the client and server: ```sh $ npm install ``` -Run the server, which will listen on port 50051: + +Run the server: ```sh $ node ./dynamic_codegen/route_guide/route_guide_server.js --db_path=./dynamic_codegen/route_guide/route_guide_db.json ``` -Run the client (in a different terminal): + +From a different terminal, run the client: ```sh $ node ./dynamic_codegen/route_guide/route_guide_client.js --db_path=./dynamic_codegen/route_guide/route_guide_db.json diff --git a/content/docs/tutorials/basic/objective-c.md b/content/docs/tutorials/basic/objective-c.md index d0dffef..eb9eb64 100644 --- a/content/docs/tutorials/basic/objective-c.md +++ b/content/docs/tutorials/basic/objective-c.md @@ -134,22 +134,22 @@ service method, all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server and receives a response later, just like a normal remote procedure call. -```protobuf -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *response-streaming RPC* where the client sends a request to the server and gets back a stream of response messages. You specify a response-streaming method by placing the `stream` keyword before the *response* type. -```protobuf -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *request-streaming RPC* where the client sends a sequence of messages to the server. Once the client has finished writing the messages, it waits for the @@ -157,11 +157,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} request-streaming method by placing the `stream` keyword before the *request* type. -```protobuf -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages to the other. The two streams operate independently, so clients and servers @@ -172,13 +172,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```protobuf -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: @@ -385,7 +385,7 @@ GRPCUnaryResponseHandler *handler = } } responseDispatchQueue:nil]; -GRPCStreamingProtoCall *call = +GRPCStreamingProtoCall *call = [service recordRouteWithResponseHandler:handler callOptions:nil]; [call start]; [call writeMessage:point1]; diff --git a/content/docs/tutorials/basic/php.md b/content/docs/tutorials/basic/php.md index 92e27fd..8bc6d05 100644 --- a/content/docs/tutorials/basic/php.md +++ b/content/docs/tutorials/basic/php.md @@ -124,22 +124,22 @@ service method, all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server and receives a response later, just like a normal remote procedure call. -```protobuf -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *response-streaming RPC* where the client sends a request to the server and gets back a stream of response messages. You specify a response-streaming method by placing the `stream` keyword before the *response* type. -```protobuf -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *request-streaming RPC* where the client sends a sequence of messages to the server. Once the client has finished writing the messages, it waits for the @@ -147,11 +147,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} request-streaming method by placing the `stream` keyword before the *request* type. -```protobuf -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages to the other. The two streams operate independently, so clients and servers @@ -162,13 +162,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```protobuf -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: diff --git a/content/docs/tutorials/basic/python.md b/content/docs/tutorials/basic/python.md index 28505be..339da51 100644 --- a/content/docs/tutorials/basic/python.md +++ b/content/docs/tutorials/basic/python.md @@ -83,10 +83,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```protobuf -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *response-streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from the @@ -94,13 +94,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a response-streaming method by placing the `stream` keyword before the *response* type. -```protobuf -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *request-streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client has @@ -108,11 +108,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} return its response. You specify a request-streaming method by placing the `stream` keyword before the *request* type. -```protobuf -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectionally-streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -123,13 +123,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```protobuf -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Your .proto file also contains protocol buffer message type definitions for all +Your `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: @@ -394,13 +394,13 @@ for received_route_note in stub.RouteChat(sent_route_note_iterator): ### Try it out! -Run the server, which will listen on port 50051: +Run the server: ```sh $ python route_guide_server.py ``` -Run the client (in a different terminal): +From a different terminal, run the client: ```sh $ python route_guide_client.py diff --git a/content/docs/tutorials/basic/ruby.md b/content/docs/tutorials/basic/ruby.md index 43299b8..bc0254b 100644 --- a/content/docs/tutorials/basic/ruby.md +++ b/content/docs/tutorials/basic/ruby.md @@ -83,10 +83,10 @@ all of which are used in the `RouteGuide` service: - A *simple RPC* where the client sends a request to the server using the stub and waits for a response to come back, just like a normal function call. -```protobuf -// Obtains the feature at a given position. -rpc GetFeature(Point) returns (Feature) {} -``` + ```protobuf + // Obtains the feature at a given position. + rpc GetFeature(Point) returns (Feature) {} + ``` - A *server-side streaming RPC* where the client sends a request to the server and gets a stream to read a sequence of messages back. The client reads from @@ -94,13 +94,13 @@ rpc GetFeature(Point) returns (Feature) {} example, you specify a server-side streaming method by placing the `stream` keyword before the *response* type. -```protobuf -// Obtains the Features available within the given Rectangle. Results are -// streamed rather than returned at once (e.g. in a response message with a -// repeated field), as the rectangle may cover a large area and contain a -// huge number of features. -rpc ListFeatures(Rectangle) returns (stream Feature) {} -``` + ```protobuf + // Obtains the Features available within the given Rectangle. Results are + // streamed rather than returned at once (e.g. in a response message with a + // repeated field), as the rectangle may cover a large area and contain a + // huge number of features. + rpc ListFeatures(Rectangle) returns (stream Feature) {} + ``` - A *client-side streaming RPC* where the client writes a sequence of messages and sends them to the server, again using a provided stream. Once the client @@ -108,11 +108,11 @@ rpc ListFeatures(Rectangle) returns (stream Feature) {} and return its response. You specify a client-side streaming method by placing the `stream` keyword before the *request* type. -```protobuf -// Accepts a stream of Points on a route being traversed, returning a -// RouteSummary when traversal is completed. -rpc RecordRoute(stream Point) returns (RouteSummary) {} -``` + ```protobuf + // Accepts a stream of Points on a route being traversed, returning a + // RouteSummary when traversal is completed. + rpc RecordRoute(stream Point) returns (RouteSummary) {} + ``` - A *bidirectional streaming RPC* where both sides send a sequence of messages using a read-write stream. The two streams operate independently, so clients @@ -123,13 +123,13 @@ rpc RecordRoute(stream Point) returns (RouteSummary) {} stream is preserved. You specify this type of method by placing the `stream` keyword before both the request and the response. -```protobuf -// Accepts a stream of RouteNotes sent while a route is being traversed, -// while receiving other RouteNotes (e.g. from other users). -rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} -``` + ```protobuf + // Accepts a stream of RouteNotes sent while a route is being traversed, + // while receiving other RouteNotes (e.g. from other users). + rpc RouteChat(stream RouteNote) returns (stream RouteNote) {} + ``` -Our .proto file also contains protocol buffer message type definitions for all +Our `.proto` file also contains protocol buffer message type definitions for all the request and response types used in our service methods - for example, here's the `Point` message type: @@ -376,23 +376,28 @@ streams operate completely independently. ### Try it out! -Build client and server: +Work from the example directory: + +```sh +$ cd examples/ruby +``` + +Build the client and server: ```sh -$ # from examples/ruby $ gem install bundler && bundle install ``` -Run the server, which will listen on port 50051: + +Run the server: ```sh -$ # from examples/ruby $ bundle exec route_guide/route_guide_server.rb ../python/route_guide/route_guide_db.json -$ # (note that the route_guide_db.json file is actually language-agnostic; it's just -$ # located in the python folder). ``` -Run the client (in a different terminal): + +> Note: The `route_guide_db.json` file is actually language-agnostic, it happens to be located in the `python` folder. + +From a different terminal, run the client: ```sh -$ # from examples/ruby $ bundle exec route_guide/route_guide_client.rb ../python/route_guide/route_guide_db.json ``` diff --git a/content/docs/tutorials/basic/web.md b/content/docs/tutorials/basic/web.md index ac46c41..1f167c4 100644 --- a/content/docs/tutorials/basic/web.md +++ b/content/docs/tutorials/basic/web.md @@ -32,7 +32,6 @@ protocol buffers, including efficient serialization, a simple IDL, and easy interface updating. gRPC-Web lets you access gRPC services built in this manner from browsers using an idiomatic API. - ### Define the Service @@ -74,7 +73,6 @@ function doEcho(call, callback) { } ``` - ### Configure the Envoy Proxy In this example, we will use the [Envoy](https://www.envoyproxy.io/) @@ -119,15 +117,11 @@ this: You may also need to add some CORS setup to make sure the browser can request cross-origin content. - In this simple example, the browser makes gRPC requests to port `:8080`. Envoy forwards the request to the backend gRPC server listening on port `:9090`. - - ### Generate Protobuf Messages and Service Client Stub - To generate the protobuf message classes from our `echo.proto`, run the following command: @@ -163,7 +157,6 @@ In the `--grpc-web_out` param above: Our command generates the client stub, by default, to the file `echo_grpc_web_pb.js`. - ### Write JS Client Code Now you are ready to write some JS client code. Put this in a `client.js` file. @@ -201,7 +194,6 @@ You will need a `package.json` file ### Compile the JS Library - Finally, putting all these together, we can compile all the relevant JS files into one single JS library that can be used in the browser. @@ -212,6 +204,5 @@ $ npx webpack client.js Now embed `dist/main.js` into your project and see it in action! - [protobuf documentation]:https://developers.google.com/protocol-buffers/ [main page]:/docs/