Skip to content

Commit

Permalink
Merge pull request #201 from Smartmind12/patch-10
Browse files Browse the repository at this point in the history
Update transforming-responses.md
  • Loading branch information
oleg-nenashev authored Oct 2, 2023
2 parents b7a2c02 + 7910605 commit 9cdc5ea
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions _docs/extensibility/transforming-responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ intend to register them via an instance as described below.

Parameters are supplied on a per stub mapping basis:

{% codetabs %}

{% codetab Java %}

```java
stubFor(get(urlEqualTo("/transform")).willReturn(
aResponse()
.withTransformerParameter("newValue", 66)
.withTransformerParameter("inner", ImmutableMap.of("thing", "value")))); // ImmutableMap is from Guava, but any Map will do
```

or:
{% endcodetab %}

{% codetab JSON %}

```json
{
Expand All @@ -91,6 +97,10 @@ or:
}
```

{% endcodetab %}

{% endcodetabs %}

### Non-global transformations

By default transformations will be applied globally. If you only want
Expand All @@ -106,14 +116,20 @@ public boolean applyGlobally() {

Then you add the transformation to specific stubs via its name:

{% codetabs %}

{% codetab Java %}

```java
stubFor(get(urlEqualTo("/local-transform")).willReturn(aResponse()
.withStatus(200)
.withBody("Original body")
.withTransformers("my-transformer", "other-transformer")));
```

or:
{% endcodetab %}

{% codetab JSON %}

```json
{
Expand All @@ -128,6 +144,9 @@ or:
}
}
```
{% endcodetab %}

{% endcodetabs %}

The Java API also has a convenience method for adding transformers and
parameters in one call:
Expand Down Expand Up @@ -163,4 +182,4 @@ public static class StubResponseTransformerWithParams extends ResponseTransforme
return "stub-transformer-with-params";
}
}
```
```

0 comments on commit 9cdc5ea

Please sign in to comment.