Hi, is there a way to change the sample data when ...
# help
u
Hi, is there a way to change the sample data when a specific request coming on wiremock.io?
l
Hi, are you referring to WireMock open source or WireMock Cloud?
u
i mean WireMock Cloud. Is there any way to change the data source's values directly after receiving a request? Thanks.
l
Data sources are read only in wiremock cloud. Could you tell me a little more about your use case so I can see if there is a way to help?
s
I'm not sure this is what they are asking about, but perhaps a similar (if not equal) use case would be to set up a mapping with one set of values, then give the ability to clone and modify that mapping more easily. For example, say I have a GET (order) happening that returns a JSON object for a particular URL. The JSON object is rather large, and I want to modify a subsection of the JSON (perhaps a zip code) while not touching all of the item / payment data. Currently, I would need to maintain a unique instance of each request locally to push up to WireMock (or set them up individually). That way if I have to change something about the base JSON, I need to modify every request. But if there was a mechanism to say do the equivalent of geting mapping X, take the json, modify it to switch out the address / zip code, then republish the mapping to create mapping Y, but doing so in more of a PATCH type operation.
u
Sure! For my use case, I want to process the following three steps: Check the credit card — Verify whether the card number exists in the data source. Each card has three attributes: • total: the total balance on the card • available: the amount that can currently be used to buy services • frozen: the amount reserved for pending purchases Reserve an amount — Before charging for a service, I want to reserve the required amount by debiting it from available and adding it to frozen. The total remains unchanged in this step. Confirm the purchase — Once the service is confirmed, the frozen amount is cleared (set to 0), and that amount is deducted from total. However, as you mentioned, WireMock doesn’t support rewriting data. The only feasible approach I can think of is using stateful mocking to simulate this process.
l
Yes, absolutely. the WireMock Cloud advanced stateful mocking sounds like it would be a good fit for this
u
I understand, thanks a lot for your support and enthusiasm!
l
No problem. If you need any further support please let me know here or via the intercom support in the app. Do you mind me asking if you are using WireMock Cloud as a company or just yourself.
u
Yes, im training in a company and my mentor recommend to use WireMock as an external service for my project
🙌 1