Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Example READMEs #2179

Merged
merged 3 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions Examples/echo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,36 @@ the four RPC types.
The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport)
HTTP/2 transport.

## Prerequisites

You must have the Protocol Buffers compiler (`protoc`) installed. You can find
the instructions for doing this in the [gRPC Swift Protobuf documentation][0].
The `swift` commands below are all prefixed with `PROTOC_PATH=$(which protoc)`,
this is to let the build system know where `protoc` is located so that it can
generate stubs for you. You can read more about it in the [gRPC Swift Protobuf
documentation][1].

## Usage

Build and run the server using the CLI:

```console
$ swift run echo serve
$ PROTOC_PATH=$(which protoc) swift run echo serve
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the comment I left on the examples, should we mention (and/or link to the plugin docs) why setting this environment variable is required?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, done!

Echo listening on [ipv4]127.0.0.1:1234
```

Use the CLI to make a unary 'Get' request against it:

```console
$ swift run echo get --message "Hello"
$ PROTOC_PATH=$(which protoc) swift run echo get --message "Hello"
get → Hello
get ← Hello
```

Use the CLI to make a bidirectional streaming 'Update' request:

```console
$ swift run echo update --message "Hello World"
$ PROTOC_PATH=$(which protoc) swift run echo update --message "Hello World"
update → Hello
update → World
update ← Hello
Expand All @@ -42,5 +51,8 @@ update ← World
Get help with the CLI by running:

```console
$ swift run echo --help
$ PROTOC_PATH=$(which protoc) swift run echo --help
```

[0]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/installing-protoc
[1]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/generating-stubs
14 changes: 13 additions & 1 deletion Examples/error-details/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,21 @@ described in more detailed in the [gRPC Error
Guide](https://grpc.io/docs/guides/error/) and is made available via the
[grpc-swift-protobuf](https://github.com/grpc-swift-protobuf) package.

## Prerequisites

You must have the Protocol Buffers compiler (`protoc`) installed. You can find
the instructions for doing this in the [gRPC Swift Protobuf documentation][0].
The `swift` commands below are all prefixed with `PROTOC_PATH=$(which protoc)`,
this is to let the build system know where `protoc` is located so that it can
generate stubs for you. You can read more about it in the [gRPC Swift Protobuf
documentation][1].

## Usage

Build and run the example using the CLI:

```console
$ swift run
$ PROTOC_PATH=$(which protoc) swift run
Error code: resourceExhausted
Error message: The greeter has temporarily run out of greetings.
Error details:
Expand All @@ -24,3 +33,6 @@ Error details:
- Help links:
- https://en.wikipedia.org/wiki/Caffeine (A Wikipedia page about caffeine including its properties and effects.)
```

[0]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/installing-protoc
[1]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/generating-stubs
18 changes: 15 additions & 3 deletions Examples/hello-world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,37 @@ service which allows you to start a server and to make requests against it.
The tool uses the [SwiftNIO](https://github.com/grpc/grpc-swift-nio-transport)
HTTP/2 transport.

## Prerequisites

You must have the Protocol Buffers compiler (`protoc`) installed. You can find
the instructions for doing this in the [gRPC Swift Protobuf documentation][0].
The `swift` commands below are all prefixed with `PROTOC_PATH=$(which protoc)`,
this is to let the build system know where `protoc` is located so that it can
generate stubs for you. You can read more about it in the [gRPC Swift Protobuf
documentation][1].

## Usage

Build and run the server using the CLI:

```console
$ swift run hello-world serve
$ PROTOC_PATH=$(which protoc) swift run hello-world serve
Greeter listening on [ipv4]127.0.0.1:31415
```

Use the CLI to send a request to the service:

```console
$ swift run hello-world greet
$ PROTOC_PATH=$(which protoc) swift run hello-world greet
Hello, stranger
```

Send the name of the greetee in the request by specifying a `--name`:

```console
$ swift run hello-world greet --name "PanCakes 🐶"
$ PROTOC_PATH=$(which protoc) swift run hello-world greet --name "PanCakes 🐶"
Hello, PanCakes 🐶
```

[0]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/installing-protoc
[1]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/generating-stubs
12 changes: 12 additions & 0 deletions Examples/reflection-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ protoc --descriptor_set_out=path/to/output.pb path/to/input.proto \
--include_imports
```

## Prerequisites

You must have the Protocol Buffers compiler (`protoc`) installed. You can find
the instructions for doing this in the [gRPC Swift Protobuf documentation][0].
The `swift` commands below are all prefixed with `PROTOC_PATH=$(which protoc)`,
this is to let the build system know where `protoc` is located so that it can
generate stubs for you. You can read more about it in the [gRPC Swift Protobuf
documentation][1].

## Usage

Build and run the server using the CLI:
Expand Down Expand Up @@ -59,3 +68,6 @@ $ grpcurl -plaintext -d '{ "text": "Hello" }' 127.0.0.1:31415 echo.Echo.Get
"text": "Hello"
}
```

[0]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/installing-protoc
[1]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/generating-stubs
16 changes: 14 additions & 2 deletions Examples/route-guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,28 @@ HTTP/2 transport.
This example has an accompanying tutorial hosted on the [Swift Package
Index](https://swiftpackageindex.com/grpc/grpc-swift/main/tutorials/grpccore/route-guide).

## Prerequisites

You must have the Protocol Buffers compiler (`protoc`) installed. You can find
the instructions for doing this in the [gRPC Swift Protobuf documentation][0].
The `swift` commands below are all prefixed with `PROTOC_PATH=$(which protoc)`,
this is to let the build system know where `protoc` is located so that it can
generate stubs for you. You can read more about it in the [gRPC Swift Protobuf
documentation][1].

## Usage

Build and run the server using the CLI:

```console
$ swift run route-guide serve
$ PROTOC_PATH=$(which protoc) swift run route-guide serve
server listening on [ipv4]127.0.0.1:31415
```

Use the CLI to interrogate the different RPCs you can call:

```console
$ swift run route-guide --help
$ PROTOC_PATH=$(which protoc) swift run route-guide --help
USAGE: route-guide <subcommand>

OPTIONS:
Expand All @@ -42,3 +51,6 @@ SUBCOMMANDS:

See 'route-guide help <subcommand>' for detailed help.
```

[0]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/installing-protoc
[1]: https://swiftpackageindex.com/grpc/grpc-swift-protobuf/documentation/grpcprotobuf/generating-stubs
Loading