Sobes.tech
Junior

How do you pass a URL value as a parameter in Retrofit?

sobes.tech AI

Answer from AI

// Example API interface
interface MyApi {

    @GET
    suspend fun getDataFromUrl(@Url url: String): Response<MyData>
}

Use the @Url annotation on a method parameter in the Retrofit2 interface. This allows passing a full URL as an argument to the function, which is convenient for fetching data from dynamic addresses. Retrofit will not use the base URL specified in the Builder.

How do you pass a URL value as a parameter in… - sobes.tech