Return same request body #229

Closed
opened 2025-12-29 14:25:50 +01:00 by adam · 8 comments
Owner

Originally created by @hsnsalhi on GitHub (Nov 29, 2019).

Hello,
In the response.body I want to return the same request.body
For that I use the transformer but it transforms quotes too.
Here is an example:

{
  "Request": {
    "Path": {
      "Matchers": [
        {
          "Name": "WildcardMatcher",
          "Pattern": "/test"
        }
      ]
    },
    "Methods": [
      "post"
    ]
  },
  "Response": {
    "StatusCode": 300,
    
    "Body": "{{request.body}}",
    "UseTransformer": true
  }
}

When I test with

{
  "key":"value"
}

I get

{
  "key":"value"
}
Originally created by @hsnsalhi on GitHub (Nov 29, 2019). Hello, In the response.body I want to return the same request.body For that I use the transformer but it transforms quotes too. Here is an example: ``` js { "Request": { "Path": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "/test" } ] }, "Methods": [ "post" ] }, "Response": { "StatusCode": 300, "Body": "{{request.body}}", "UseTransformer": true } } ``` When I test with ``` { "key":"value" } ``` I get ``` { "key":"value" } ```
adam added the feature label 2025-12-29 14:25:50 +01:00
adam closed this issue 2025-12-29 14:25:50 +01:00
Author
Owner

@StefH commented on GitHub (Nov 29, 2019):

Can you try BodyAsJson?

@StefH commented on GitHub (Nov 29, 2019): Can you try BodyAsJson?
Author
Owner

@hsnsalhi commented on GitHub (Nov 29, 2019):

I get an exception

Providing a Response for Mapping 'fe1a2e88-e7a2-4404-a8c9-5186b42ec731' failed. HttpStatusCode set to 500. Exception: System.ArgumentException: Object serialized to String. JObject instance expected.

@hsnsalhi commented on GitHub (Nov 29, 2019): I get an exception > Providing a Response for Mapping 'fe1a2e88-e7a2-4404-a8c9-5186b42ec731' failed. HttpStatusCode set to 500. Exception: System.ArgumentException: Object serialized to String. JObject instance expected.
Author
Owner

@StefH commented on GitHub (Nov 30, 2019):

1]
Use the triple-stash syntax: {{{request.body}}} --> https://github.com/rexm/Handlebars.Net/issues/55

2]
Try new preview NuGet: WireMock.Net.1.0.38-ci-12259.nupkg

@StefH commented on GitHub (Nov 30, 2019): 1] Use the triple-stash syntax: `{{{request.body}}}` --> https://github.com/rexm/Handlebars.Net/issues/55 2] Try new preview NuGet: `WireMock.Net.1.0.38-ci-12259.nupkg`
Author
Owner

@StefH commented on GitHub (Dec 3, 2019):

@hsnsalhi Can you try if this version solves your issue?

@StefH commented on GitHub (Dec 3, 2019): @hsnsalhi Can you try if this version solves your issue?
Author
Owner

@StefH commented on GitHub (Dec 6, 2019):

@hsnsalhi Did you time to test this one?

@StefH commented on GitHub (Dec 6, 2019): @hsnsalhi Did you time to test this one?
Author
Owner

@StefH commented on GitHub (Dec 10, 2019):

@hsnsalhi Can you please test?

@StefH commented on GitHub (Dec 10, 2019): @hsnsalhi Can you please test?
Author
Owner

@StefH commented on GitHub (Dec 17, 2019):

@hsnsalhi Can you please test?

@StefH commented on GitHub (Dec 17, 2019): @hsnsalhi Can you please test?
Author
Owner

@StefH commented on GitHub (Dec 26, 2019):

PR merged to master.

@StefH commented on GitHub (Dec 26, 2019): PR merged to master.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#229