How to mock a all sub paths?
eloo opened this issue ยท 6 comments
Hi,
i've just found your project and really like the simplicity.
But i have trouble to mock responses for requests with unknown paths.
For example i want to mock the following requests:
- /api
- /api/23
- /something/...
and so on..
and i have tried a pattern like this
...
"endpoint": "/{*}"
...
But this would only match /api
and not its sub-paths.
So is this currently possible? Something like a "catch-all" endpoint?
Thanks
Hi @eloo,
Killgrave relies on gorilla/mux
matcher to route requests. More specifically, it uses HandleFunc(path string, f func(http.ResponseWriter, *http.Request))
, so based on this StackOverflow thread, I guess it's not possible nowadays.
Bit of annoying, I know, but I hope the amount of subpaths
your API supports is not infinite (nor very large), so I guess defining multiple paths (as suggested on the aforementioned SO question) would do the work.
I guess in the future we could add a specific edge case to handle some specific wildcard and use HandlerFunc(f func(http.ResponseWriter, *http.Request))
with a pre-defined "match all" function for those cases.
Please, open a new issue specific issue to request that, with all the details and feel free to contribute with the corresponding pull requests, you're more than welcome ๐
Thanks!!!
Hi @joanlopez
thanks for the clarification.
But sadly the amount of subpaths is not directly know or hard to find out because in our case we want to mock/block a whole infrastructure behind killgrave ;)
So if you could add this edge case function i guess it would be useful for others as well.
Further i have found that the chi-router is capable of wildcards. Not sure about the other feature you use currently in gorrila/mux but maybe challanging gorrila/mux here could be an option?
Thanks
+1 for this.. its a fairly common feature.. just need a 200 response
Great, thanks for letting us now! We'll increase the priority of this issue and start to work on it sooner than later! ๐๐ป
๐ really great little service this btw! thank you so much
Hi.
I had the same issue for creating wild paths.
So I forked this project and made a change.
Now the wild path is supported using this project. You need to set the value of endpoint to "/" to handle all incoming request from any path.
Remember that you should add your explicit route first and then add your wild paths. For example if you have a explicit path called "api/hello" and a wild card path, you should define your "/api/hello" first and then define your wild card path.
Also you can change the endpoint value from "/" to anything you want, if you think the "/" has another application for you.
Link of the forked project: https://github.com/alinowrouzii/killgrave