I have some service urls with the same baseUrl. For some urls there will be some common used parameters, for example an apiVersion
or locale
. But they don't have to be in every url, so I can't add them to the baseUrl.
.../api/{apiVersion}/{locale}/event/{eventId}
.../api/{apiVersion}/{locale}/venues
.../api/{apiVersion}/configuration
I don't want to add these parameters in the retrofit interface. In retrofit 1, I made an interceptor and used RequestFacade.addPathParam(..., ...)
to fill these common path parameters for every url.
For retrofit 2, I can't seem to find a proper way to do this with okhttp. The only way I see this being possible right now is to get the HttpUrl
from Chain.request().httpUrl();
in an okhttp Interceptor
and manipulate that one myself, but I don't know if this is the best way to go.
Has anyone come across a better way to replace path parameters in an okhttp Interceptor
?
At the time of writing I'm using retrofit:2.0.0-beta2 and okhttp:2.7.2.