gmazzo/okhttp-client-mock

MockInterceptor rules - matches request body

Closed this issue · 1 comments

hi All, when adding rules to MockInterceptor for returning a different response based on the request body for a post request, I was hoping to do something like this:

interceptor.addRule().post(url).requestBody(json1).anyTimes().respond(respondJson1); interceptor.addRule().post(url).requestBody(json2)..anyTimes().respond(respondJson2);

Is this something that can be added to the repo?
I can try open a PR

I think a BodyMatcher can be added to support this use case, but it's not trivial. You'll probably have to cache the Body because it's possible it's not repeatable (like an InputStream).
Then you can have some overload function to assert it as a String, or whatever makes sense.