Admin static json mappings #20

Closed
opened 2025-12-29 14:21:05 +01:00 by adam · 13 comments
Owner

Originally created by @phillee007 on GitHub (Feb 10, 2017).

Originally assigned to: @StefH on GitHub.

Hi there,

I've downloaded the source zip, built the solution, and created an /__admin/mappings/ folder under the bin/debug folder for the WireMock.Net.StandAlone project. In there, I copied the basic json file from http://wiremock.org/docs/stubbing/ (as shown at the end) and named it test.json. I then ran the standalone project from the command line (after adding Newtonsoft.Json reference and restoring Nuget packages). The console runner shows the server is now listening on port 9090.

When I tried to browse to http://localhost:9090/some/thing it said "No mapping found", and also when I browse to http://localhost:9090/__admin/mappings it returned an empty array. Is it loading up the static json file mappings?

Thanks,
Phil

{
"request": {
"method": "GET",
"url": "/some/thing"
},
"response": {
"status": 200,
"body": "Hello world!",
"headers": {
"Content-Type": "text/plain"
}
}
}

Originally created by @phillee007 on GitHub (Feb 10, 2017). Originally assigned to: @StefH on GitHub. Hi there, I've downloaded the source zip, built the solution, and created an /__admin/mappings/ folder under the bin/debug folder for the WireMock.Net.StandAlone project. In there, I copied the basic json file from http://wiremock.org/docs/stubbing/ (as shown at the end) and named it test.json. I then ran the standalone project from the command line (after adding Newtonsoft.Json reference and restoring Nuget packages). The console runner shows the server is now listening on port 9090. When I tried to browse to http://localhost:9090/some/thing it said "No mapping found", and also when I browse to http://localhost:9090/__admin/mappings it returned an empty array. Is it loading up the static json file mappings? Thanks, Phil { "request": { "method": "GET", "url": "/some/thing" }, "response": { "status": 200, "body": "Hello world!", "headers": { "Content-Type": "text/plain" } } }
adam added the feature label 2025-12-29 14:21:05 +01:00
adam closed this issue 2025-12-29 14:21:05 +01:00
Author
Owner

@StefH commented on GitHub (Feb 10, 2017):

WireMock.Net.StandAlone
There should be no need for Newtonsoft.Json; I did fix the app.config

@StefH commented on GitHub (Feb 10, 2017): **WireMock.Net.StandAlone** There should be no need for Newtonsoft.Json; I did fix the app.config
Author
Owner

@StefH commented on GitHub (Feb 10, 2017):

Static Mappings using a json file is not yet implemented. I'll build this in some time using this thread for updates.

@StefH commented on GitHub (Feb 10, 2017): **Static Mappings** using a json file is not yet implemented. I'll build this in some time using this thread for updates.
Author
Owner

@StefH commented on GitHub (Feb 10, 2017):

Support added.

See example project on how to use this.

@StefH commented on GitHub (Feb 10, 2017): Support added. See example project on how to use this.
Author
Owner

@phillee007 commented on GitHub (Feb 10, 2017):

Nice :-)

I added a method to do it myself but hadn't tested enough to submit a PR.
Will get the latest when I'm back at work on Monday and try it out

Thanks!

On 10/02/2017 9:16 PM, "Stef Heyenrath" notifications@github.com wrote:

Support added.

See example project onhow to use this.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/StefH/WireMock.Net/issues/21#issuecomment-278883659,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AEEFo1sFxFLZxkl-WZCNEiwxYz9UAt_Uks5rbBzAgaJpZM4L8zMR
.

@phillee007 commented on GitHub (Feb 10, 2017): Nice :-) I added a method to do it myself but hadn't tested enough to submit a PR. Will get the latest when I'm back at work on Monday and try it out Thanks! On 10/02/2017 9:16 PM, "Stef Heyenrath" <notifications@github.com> wrote: Support added. See example project onhow to use this. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub <https://github.com/StefH/WireMock.Net/issues/21#issuecomment-278883659>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AEEFo1sFxFLZxkl-WZCNEiwxYz9UAt_Uks5rbBzAgaJpZM4L8zMR> .
Author
Owner

@StefH commented on GitHub (Feb 13, 2017):

Did you have time to verify this?

@StefH commented on GitHub (Feb 13, 2017): Did you have time to verify this?
Author
Owner

@StefH commented on GitHub (Mar 4, 2017):

@phillee007 Is it working fine?

@StefH commented on GitHub (Mar 4, 2017): @phillee007 Is it working fine?
Author
Owner

@phillee007 commented on GitHub (Mar 15, 2017):

finally got a chance to test this!

To answer your question: yes and no...

Yes it can read mappings files that are named using a guid, however, we find it useful to actually use meaningful file names, as we're generating a whole heap of static mappings based on log files from real requests/responses from our external api. E.g. customer_get_123.json vs asdfdsafsaf234324.json

Is it possible for the static mappings reader to just read all .json files in the directory rather than forcing them to use a guid? Maybe add an optional filename property to the Mapping class so we can specify that if/when calling the admin api to add mappings at runtime too?

Thanks,
Phil

@phillee007 commented on GitHub (Mar 15, 2017): finally got a chance to test this! To answer your question: yes and no... Yes it can read mappings files that are named using a guid, however, we find it useful to actually use meaningful file names, as we're generating a whole heap of static mappings based on log files from real requests/responses from our external api. E.g. customer_get_123.json vs asdfdsafsaf234324.json Is it possible for the static mappings reader to just read all .json files in the directory rather than forcing them to use a guid? Maybe add an optional filename property to the Mapping class so we can specify that if/when calling the admin api to add mappings at runtime too? Thanks, Phil
Author
Owner

@StefH commented on GitHub (Mar 15, 2017):

Good point.

I will add support for all .json files and add a title to the mapping which will be used as filename if present.

@StefH commented on GitHub (Mar 15, 2017): Good point. I will add support for all `.json` files and add a `title` to the mapping which will be used as filename if present.
Author
Owner

@StefH commented on GitHub (Mar 15, 2017):

OK. I've added a "Title" as property. Can you please get the latest code and test if this works for you ?

@StefH commented on GitHub (Mar 15, 2017): OK. I've added a "Title" as property. Can you please get the latest code and test if this works for you ?
Author
Owner

@StefH commented on GitHub (Apr 14, 2017):

Were you able to test the latest code?

@StefH commented on GitHub (Apr 14, 2017): Were you able to test the latest code?
Author
Owner

@phillee007 commented on GitHub (Apr 28, 2017):

Good news - I got to test this at last and it does work! Will raise another issue regarding the path matching and full urls separately

@phillee007 commented on GitHub (Apr 28, 2017): Good news - I got to test this at last and it does work! Will raise another issue regarding the path matching and full urls separately
Author
Owner

@phillee007 commented on GitHub (Apr 28, 2017):

Actually, scratch that comment re raising another issue. I see you've already added in the extra function to convert a relative url to the fully qualified url so that matcher works :-)

E.g. If the request has something like this:
...
Url": {
"Matchers": [
{
"Name": "WildcardMatcher",
"Pattern": "products/123456"
}
]
},
...

When I was using the earlier version of wiremock.net, it required me to have the fully-qualified url in the Pattern otherwise it wouldn't find the match when I requested http://myserver:9090/products/123456. E.g.

...
"Pattern": "http://myserver:9090/products/123456"
...

However, I see now that I can just specify the relative url and it works as per the regular WireMock documentation.

Great work!!! We're now ready to use this fairly heavily so will let you know if we hit any other issues

@phillee007 commented on GitHub (Apr 28, 2017): Actually, scratch that comment re raising another issue. I see you've already added in the extra function to convert a relative url to the fully qualified url so that matcher works :-) E.g. If the request has something like this: ... Url": { "Matchers": [ { "Name": "WildcardMatcher", "Pattern": "products/123456" } ] }, ... When I was using the earlier version of wiremock.net, it required me to have the fully-qualified url in the Pattern otherwise it wouldn't find the match when I requested http://myserver:9090/products/123456. E.g. ... "Pattern": "http://myserver:9090/products/123456" ... However, I see now that I can just specify the relative url and it works as per the regular WireMock documentation. Great work!!! We're now ready to use this fairly heavily so will let you know if we hit any other issues
Author
Owner

@StefH commented on GitHub (Apr 28, 2017):

Thanks. Please open new issues in case you encounter something.

@StefH commented on GitHub (Apr 28, 2017): Thanks. Please open new issues in case you encounter something.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net-wiremock#20