I'm trying to add Retrofit to an app that's calling Google Cloud APIs using custom methods
An example of a custom method would be: https://service.name/v1/name:customVerb
The problem I'm having is that Retrofit doesn't like the colon (":") in the URL. With the above URL, I'd get the following exception:
Exception caught while executingjava.lang.IllegalArgumentException: Malformed URL. Base: https://service.name/v1/, Relative: name:customVerb
I've tried a few things such as using @Path annotation as well as setting name:customVerb directly in the call type:
@GET("name:customVerb")
or
@GET("{customMethod}")
fun getCustomTest(
@Path("customMethod") s: String
but unfortunately neither of those worked.
I've also tried encoding ":" but the API doesn't like that and returns a 404. Setting aside the conversation of the value of these custom methods, is there any specific reason for not supporting colons in retrofit as part of the URL? Also maybe there's a workaround that I'm not aware of?
Try this: ./name:customVerb.
Retrofit interprets the path argument as a relative URL. But name:customVerb reads like a scheme. Imagine the name was https or mailto or another scheme name.
@swankjesse you are amazing :) thank you so much - your solution works perfectly! It makes sense that colon indicates a schema, and hopefully this thread will help anyone else trying to use custom methods with Retrofit.
Any solution to this yet?. I'm trying to do a POST but I'm getting the same exception. I tried the solution by @swankjesse but still no luck
Most helpful comment
Try this:
./name:customVerb.Retrofit interprets the path argument as a relative URL. But
name:customVerbreads like a scheme. Imagine the name washttpsormailtoor another scheme name.