diff --git a/_config.yml b/_config.yml index 8972854d..fb5f53c9 100644 --- a/_config.yml +++ b/_config.yml @@ -238,7 +238,7 @@ wiremock_version: 3.9.1 wiremock_baseline: 3.x pageEditPrefix: https://github.com/wiremock/wiremock.org/edit/main/ -grpc_extension_version: 0.6.0 +grpc_extension_version: 0.7.0 community_slack: join_url: https://slack.wiremock.org/ diff --git a/_docs/grpc.md b/_docs/grpc.md index 7d264bc3..5c878498 100644 --- a/_docs/grpc.md +++ b/_docs/grpc.md @@ -45,9 +45,9 @@ Maven: ``` -Create a root directory for WireMock e.g. `src/test/resources/wiremock` and create a subdirectory under this named `grpc`. +Create a root directory for WireMock, typically `src/test/resources/wiremock`, and create a subdirectory in it named `grpc`. -Put the descriptor files generated by `protoc` from your `.proto` files into the `grpc` directory. +Copy the descriptor files generated by `protoc` from your `.proto` files into the `grpc` subdirectory. Initialise WireMock server with the extension enabled and the root directory set to the path created in the previous steps: @@ -72,7 +72,7 @@ WireMockGrpcService mockGreetingService = ### Stubbing via JSON matching + responses -To specify request criteria and response data via JSON: +To specify request criteria and response data using JSON: ```java mockGreetingService.stubFor( @@ -81,8 +81,9 @@ mockGreetingService.stubFor( .willReturn(json("{ "greeting": "Hi Tom from JSON" }"))); ``` +Or, with a templated response: -Or with a templated response: +{% raw %} ```java mockGreetingService.stubFor( @@ -93,6 +94,8 @@ mockGreetingService.stubFor( "{ \"greeting\": \"Hello {{jsonPath request.body '$.name'}}\" }"))); ``` +{% endraw %} + ### Stubbing via Java message objects Matching and stubbing in the Java DSL can also be specified using the Java classes generated by `protoc`: @@ -126,13 +129,13 @@ For a more complete set of examples, see the [Java demo project](https://github. ### Setup -Download the standalone JAR at version 3.2.0 or above +Download the standalone JAR at version 3.2.0 or above and the gRPC extension JAR into your working directory. -Create a WireMock data directory with a subdirectory for stub mappings and one for descriptor files: +Create a WireMock data directory with two subdirectories; one for stub mappings, and another for descriptor files: ```bash -mkdir -p wiremock/mappings wiremock/grpc +mkdir -p wiremock wiremock/mappings wiremock/grpc ``` Compile your proto files into descriptors: @@ -141,12 +144,12 @@ Compile your proto files into descriptors: protoc --descriptor_set_out wiremock/grpc/services.dsc ExampleServices.proto ``` -Run WireMock with both on the classpath: +Run WireMock, with both directories you just created on the classpath: ```bash -java -cp wiremock-standalone-{{ site.wiremock_version }}.jar:wiremock-grpc-extension-standalone-{{ site.grpc_extension_version }}.jar \ +java -cp wiremock-standalone-{{ versions.wiremock_version }}.jar:wiremock-grpc-extension-standalone-{{ versions.grpc_extension_version }}.jar \ wiremock.Run \ - --root-dir wiremock-data + --root-dir wiremock ``` ### Stubbing @@ -172,6 +175,10 @@ gRPC stubs are defined using WireMock's standard JSON format. Requests should al } ``` +## Reloading gRPC descriptor files + +If you plan to update your gRPC descriptor files at runtime, you can inform WireMock to reload all file descriptors via a POST to the admin API endpoint `/__admin/ext/grpc/reset`. + ## More Demos -For more see the [standalone demo project](https://github.com/wiremock/wiremock-grpc-demos/tree/main/standalone). \ No newline at end of file +For more see the [standalone demo project](https://github.com/wiremock/wiremock-grpc-demos/tree/main/standalone).