jarcoal/httpmock

url parameters

PumpkinSeed opened this issue · 4 comments

I would implement a mock for our api but there is a huge amount url params what I also have to implement/mock in this case:

httpmock.RegisterResponder("GET", "https://domain/partners/cases/1234",
	...
)

So the 1234 should be a place where I can get the id of the resource.

httpmock.RegisterResponder("GET", "https://domain/partners/cases/{id}",
	...
)

Is there any chance to have it working somehow?

That would be a great addition to the library!

The matching of responders is done here so this part would need to be extended to support replacement strings or regular expressions. Perhaps regexp would be the easiest to support actually. You would then have to specify something like this for your use case:

httpmock.RegisterResponder("GET", `https://domain/partners/cases/\d+`,
	...
)

And all responders keys would have to be looped through to find a match, so regexp matching should probably be opt-in for performance reasons.

Personally, I don't have time to work on this right now, but any pull request that could solve this problem without breaking compatibility would be very welcome :-)

@PumpkinSeed better late than never, see #73

@maxatome At least it's there and we can count with it. :) Thanks

#73 merged, new release v1.0.4 available.