Response Templating examples #362

Closed
opened 2025-12-29 08:26:56 +01:00 by adam · 5 comments
Owner

Originally created by @devmariodiaz on GitHub (Oct 5, 2021).

Hello Stef,

I hope that is doing well.

I am trying to use Response Templating features from this amazing library, but for me is not working, I don't know if my code is bad, is possible that you could provide me some examples to do that?

This is my example:

var server = WireMockServer.Start(
               new WireMockServerSettings
               {
                   Urls = new[] { "http://localhost:9091" },
                   StartAdminInterface = true,
                   ReadStaticMappings = true,
                   WatchStaticMappings = true
               }
            );

            server.Given(Request.Create().WithPath("/mypath").UsingGet())
                 .RespondWith(
                   Response.Create()
                   .WithHeader("Content-Type", "application/json")
                   .WithBodyAsJson("{{JsonPath.SelectToken request.body \"..name\"}}")
                   .WithTransformer()
               );

Getting this result:

shorturl.at/yRVW1

Originally created by @devmariodiaz on GitHub (Oct 5, 2021). Hello Stef, I hope that is doing well. I am trying to use Response Templating features from this amazing library, but for me is not working, I don't know if my code is bad, is possible that you could provide me some examples to do that? This is my example: ``` var server = WireMockServer.Start( new WireMockServerSettings { Urls = new[] { "http://localhost:9091" }, StartAdminInterface = true, ReadStaticMappings = true, WatchStaticMappings = true } ); server.Given(Request.Create().WithPath("/mypath").UsingGet()) .RespondWith( Response.Create() .WithHeader("Content-Type", "application/json") .WithBodyAsJson("{{JsonPath.SelectToken request.body \"..name\"}}") .WithTransformer() ); ``` Getting this result: shorturl.at/yRVW1
adam added the question label 2025-12-29 08:26:56 +01:00
adam closed this issue 2025-12-29 08:26:56 +01:00
Author
Owner

@StefH commented on GitHub (Oct 5, 2021):

The shorturl is invalid?
And can you please add the request ?

@StefH commented on GitHub (Oct 5, 2021): The shorturl is invalid? And can you please add the request ?
Author
Owner

@devmariodiaz commented on GitHub (Oct 5, 2021):

Sure Stef, thanks for your fast answer, the request is:

this is using Postman
{
"name": "Mario"
}

Getting this result:

{
"Status": "Value cannot be null. (Parameter 'value')"
}

@devmariodiaz commented on GitHub (Oct 5, 2021): Sure Stef, thanks for your fast answer, the request is: this is using Postman { "name": "Mario" } Getting this result: { "Status": "Value cannot be null. (Parameter 'value')" }
Author
Owner

@StefH commented on GitHub (Oct 5, 2021):

.UsingGet() should be .UsingPost()

This works:
image

@StefH commented on GitHub (Oct 5, 2021): `.UsingGet()` should be `.UsingPost()` This works: ![image](https://user-images.githubusercontent.com/249938/136062519-9203d998-dcbf-4a83-b9b6-092e1bb881e1.png)
Author
Owner

@devmariodiaz commented on GitHub (Oct 5, 2021):

Thanks a lot, Stef.
I appreciate it. I checked it and it works. Could you please provide some examples using this feature?
In my case, I want to replace static variables in the canned data, and other use cases.

Also, could you please let me know, which version of RAML, is supported by WireMock.NET, I check the RAML version 1.0, JSON schema version 3.0, and it worked, my question is regarding other versions and other formats available.
I also tried to create an array and use this out-of-the-box setting feature "settings.NumberOfArrayItems = 5;",
but I was not able to create an array in RAML v1.0 JSON schema 4, here is the RAML code that I used and it is compiling with an error:

MicrosoftTeams-image

I need to implement almost all functionalities from WireMock.net to build a kind of mocking framework using RAML, JSON, XML, SOAP, etc. I will appreciate it.

Thanks for your support, WireMock .net is truly amazing.

@devmariodiaz commented on GitHub (Oct 5, 2021): Thanks a lot, Stef. I appreciate it. I checked it and it works. Could you please provide some examples using this feature? In my case, I want to replace static variables in the canned data, and other use cases. Also, could you please let me know, which version of RAML, is supported by WireMock.NET, I check the RAML version 1.0, JSON schema version 3.0, and it worked, my question is regarding other versions and other formats available. I also tried to create an array and use this out-of-the-box setting feature "settings.NumberOfArrayItems = 5;", but I was not able to create an array in RAML v1.0 JSON schema 4, here is the RAML code that I used and it is compiling with an error: ![MicrosoftTeams-image](https://user-images.githubusercontent.com/54611419/136067447-8c98d31e-9e33-43ce-a25b-1ee51777828f.png) I need to implement almost all functionalities from WireMock.net to build a kind of mocking framework using RAML, JSON, XML, SOAP, etc. I will appreciate it. Thanks for your support, WireMock .net is truly amazing.
Author
Owner

@StefH commented on GitHub (Oct 5, 2021):

For templates, read all the text + follow links on : https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating

About RAML : I use some standard libraries from Microsoft:
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />

If have more questions on RAML/Openapi : create a new issue.

@StefH commented on GitHub (Oct 5, 2021): For templates, read all the text + follow links on : https://github.com/WireMock-Net/WireMock.Net/wiki/Response-Templating About RAML : I use some standard libraries from Microsoft: `<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.2.3" />` If have more questions on RAML/Openapi : create a new issue.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#362