question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fluent API for RestClient MappingModel creation

See original GitHub issue

Is your feature request related to a problem? Please describe. I’m thinking about using WireMock as a container to run alongside my application during tests, and as far as I searched, looks like I have to create a mapping by instantiating a new MappingModel directly.

Describe the solution you’d like I think it would be really useful for users to have an experience similar to the fluent API to used to create requests when WireMock is used on the same process. I am no expert on the library but I imagine there would be some limitations, but for simple cases like matching a request and building a response, it would be really useful, since I wouldn’t have to learn two ways to configure mappings.

Describe alternatives you’ve considered Build the mapping model directly.

Is your feature request supported by WireMock (java version)? Please provide details. I’m not familiar with the java version, but as far as I researched, I couldn’t find anything like that yet.

Additional context I don’t if this is something that would be interesting for the main library or maybe it would be something that the creators would want the community to develop. But if this is something that is planned or wanted, I would be glad to help as I can. But as I said, I’m no expert and I’m not sure if I would be able to cover every possible scenario the current fluent API has.

I’m building a simple example and I’ll post here when I make some progress.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6

github_iconTop GitHub Comments

1reaction
StefHcommented, Aug 4, 2021

You can work-around this problem by using a FluentBuilder.ResponseModelBuilder() and then assign the value to WithResponse(...)

To support your scenario, I’ve to see if I can update the FluentBuilder. Can you create a new issue here? --> https://github.com/StefH/FluentBuilder

And for now, I’ll merge the PR and close this issue.

In case I can implement your scenario in the FluentBuilder project, I’ll post an update here and release a new WireMock.Net NuGet.

0reactions
dansparkcommented, Aug 4, 2021

Apologies for taking so long, I’ve been a bit busy. I took a look at the most recent version of the CI build, the API looks a little different, I don’t know if it made a lot of difference. My simplest setup looked like this:

			var response = await _api.PostMappingAsync(new MappingModel {
				Request = new RequestModel {
					Url = "*"
				},
				Response = new ResponseModel {
					StatusCode = (int)statusCode
				}
			});

With the modification, it looks like this:

			var requestBuilder = new FluentBuilder.MappingModelBuilder()
				.WithRequest(new RequestModel {
					Path = "*"
				})
				.WithResponse(new ResponseModel {
					StatusCode = (int)statusCode
				}).Build();

Maybe the MappingModelBuilder WithRequest and WithResponse methods could have an overload that asks for an Action<RequestModelBuilder> and Action<ResponseModelBuilder>? That way it could look like this:

			var requestBuilder = new FluentBuilder.MappingModelBuilder()
				.WithRequest(b => b.WithPath("*"))
				.WithResponse(b => b.WithStatusCode((int) statusCode)}).Build();
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fluent API - Configuring and Mapping Properties and Types
In this article. Model-Wide Settings; Property Mapping; Type Mapping; Model Used in Samples. When working with Entity Framework Code First the ...
Read more >
Same/similar fluent interface for in process and admin ...
The API for stubbing and finding requests in process is done with a fluent API while using the admin client uses object construction....
Read more >
Configure Entity Mappings using Fluent API in EF Code-First
Entity Mappings using Fluent API in EF 6​​ The Fluent API can be used to configure an entity to map it with database...
Read more >
New in Spring 6.1: RestClient
Spring Framework 6.1 M2 introduces the RestClient , a new synchronous HTTP client. As the name suggests, RestClient offers the fluent API of ......
Read more >
WireMock.Net changelog - Awesome .NET - LibHunt
#637 - Add support for AzureAD authentication for REST admin interface [feature] ... #621 - Fluent API for RestClient MappingModel creation [feature] ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found