Skip to content

Commit

Permalink
doc: put example above anything else in usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Semior001 committed Mar 10, 2024
1 parent 8ffc8e0 commit 46dcc29
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ gRoxy is a gRPC mocking server that allows you to mock gRPC services and respons

- [installation](#installation)
- [usage](#usage)
- [configuration](#configuration)
- [example](#example)
- [configuration](#configuration)
- [groxypb](#groxypb)
- [nested messages](#nested-messages)
- [enums](#enums)
Expand Down Expand Up @@ -53,6 +53,30 @@ Help Options:
-h, --help Show this help message
```

### example
The simplest configuration for a method "Stub" would look like this:

```yaml
version: 1

rules:
- match: { uri: "com.github.Semior001.groxy.example.mock.ExampleService/Stub" }
respond:
body: |
message StubResponse {
option (groxypb.target) = true; // this option specifies that the message is a response
string message = 1 [(groxypb.value) = "Hello, World!"];
int32 code = 2 [(groxypb.value) = "200"];
}
```
That's it. You just need to define the response message, mark it as a target response message via the option, and set values via the value option. The response message will be sent to the client when the client calls the "Stub" method. No need for providing protosets, no need for providing the whole set of definitions, just the message you want to send.
More importantly, if your response message contains lots of fields, which are not important for the test, you can just ignore them. gRoxy will leave them empty, and the client will not be able to distinguish between the real server and the mock server. That's ensured by the protobuf's backward compatibility.
Field is backward compatible if it's of the same type and the same number. Names of the fields and messages are not important.
### configuration
gRoxy uses a YAML configuration file to define the rules for the gRPC mocking server. The configuration file consists of the following sections:
Expand Down Expand Up @@ -154,26 +178,3 @@ message StubResponse {
map<string, string> map_field = 1 [(groxypb.value) = '{"key1": "value1", "key2": "value2"}'];
}
```

## example
The simplest configuration for a method "Stub" would look like this:

```yaml
version: 1

rules:
- match: { uri: "com.github.Semior001.groxy.example.mock.ExampleService/Stub" }
respond:
body: |
message StubResponse {
option (groxypb.target) = true; // this option specifies that the message is a response
string message = 1 [(groxypb.value) = "Hello, World!"];
int32 code = 2 [(groxypb.value) = "200"];
}
```
That's it. You just need to define the response message, mark it as a target response message via the option, and set values via the value option. The response message will be sent to the client when the client calls the "Stub" method. No need for providing protosets, no need for providing the whole set of definitions, just the message you want to send.
More importantly, if your response message contains lots of fields, which are not important for the test, you can just ignore them. gRoxy will leave them empty, and the client will not be able to distinguish between the real server and the mock server. That's ensured by the protobuf's backward compatibility.
Field is backward compatible if it's of the same type and the same number. Names of the fields and messages are not important.

0 comments on commit 46dcc29

Please sign in to comment.