Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to mock a all sub paths? #119

Open
eloo opened this issue Jan 11, 2022 · 6 comments
Open

How to mock a all sub paths? #119

eloo opened this issue Jan 11, 2022 · 6 comments
Assignees
Labels
enhancement New feature or request

Comments

@eloo
Copy link

eloo commented Jan 11, 2022

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

@joanlopez
Copy link
Member

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!!!

@eloo
Copy link
Author

eloo commented Jan 12, 2022

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

@rosscdh
Copy link

rosscdh commented Feb 2, 2022

+1 for this.. its a fairly common feature.. just need a 200 response

@joanlopez joanlopez added the enhancement New feature or request label Feb 2, 2022
@joanlopez
Copy link
Member

Great, thanks for letting us now! We'll increase the priority of this issue and start to work on it sooner than later! 👌🏻

@rosscdh
Copy link

rosscdh commented Feb 2, 2022

🙇 really great little service this btw! thank you so much

@alinowrouzii
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants