Skip to content

Commit

Permalink
requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangoerdes committed Sep 5, 2024
1 parent b4a5ac2 commit c779ad3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
18 changes: 7 additions & 11 deletions distribution/examples/message-transformation/replace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,19 @@ The `Replace`plugin allows you to modify values in your JSON by using a `jsonPat
```shell
curl localhost:2000 \
-H "Content-Type: application/json" \
-d '{"shop": {"name": "MyShop", "location": "Berlin"}}'
```
3. Check the console, and you'll notice that the JSON with the name field set to `foo` is logged.
```
[RouterThread /127.0.0.1:33632] INFO com.predic8.membrane.core.interceptor.LogInterceptor - Body:
[RouterThread /127.0.0.1:33632] INFO com.predic8.membrane.core.interceptor.LogInterceptor - {"shop":{"name":"foo","location":"Berlin"}}
[RouterThread /127.0.0.1:33632] INFO com.predic8.membrane.core.interceptor.LogInterceptor - ================
[RouterThread /127.0.0.1:33632] INFO com.predic8.membrane.core.interceptor.LogInterceptor - ==== Response ===
[RouterThread /127.0.0.1:33632] INFO com.predic8.membrane.core.interceptor.LogInterceptor - HTTP/1.1 200 Ok
-d '{"user": {"name": "Alice", "age": 22}}'
```
and take a look at the output:
```json
{"user":{"name":"Bob","age":22}}
```

## Configuration

This configuration sets up an API that replaces the value of the `name` field under the `shop object` in the JSON body with "foo", before forwarding the request to a target service running on localhost at port 3000.
```xml
<api port="2000">
<replace jsonPath="$.shop.name" with="foo" />
<target host="localhost" port="3000" />
<replace jsonPath="$.user.name" with="Bob" />
<target host="localhost" port="3000" />
</api>
```
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<router>

<api port="2000">
<replace jsonPath="$.shop.name" replacement="foo" />
<replace jsonPath="$.user.name" with="Bob" />
<target host="localhost" port="3000" />
</api>

Expand Down

0 comments on commit c779ad3

Please sign in to comment.