Currently I am facing some issues with Retrofit. The URL, I am providing to RetrofitInstance
is changing for the second request. Here are the codes:
object RetrofitClientInstance{
private var retrofit: Retrofit? = null
//private const val BASE_URL = "http://api.sample.com/req/";
private const val BASE_URL = "http://test.sample.com/req/"
private const val BASE_URL_VERSION = "v1/"
fun getRetrofitInstance() : Retrofit {
if (retrofit == null) {
retrofit = Retrofit.Builder()
.baseUrl(BASE_URL + BASE_URL_VERSION)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
return this!!.retrofit!!
}
}
Here are the interface
methods for different API requests:
class UserLoginResponseReceiver{
interface GetDataService {
@FormUrlEncoded
@POST(UrlEndPoints.USER_LOGIN_BY_FACEBOOK)
fun loginUserByFacebook(@Field("access_token") last: String): Call<FbLoginResponse>
@GET(UrlEndPoints.ALL_POSTS)
fun getAllPosts() : Call<AllPostsResponse>
}
}
UrlEndPoints.kt
object UrlEndPoints {
const val USER_LOGIN_BY_FACEBOOK = "user/auth/facebook"
const val ALL_POSTS = "post"
}
For the first request (loginUserByFacebook), the URL I am getting by debugging my response is:
Which is fine and working perfectly. But for the second request (getAllPosts()) I am getting the following URL:
The "req/v1" part is completely cut off! As a result I don't get the desired response. What's the problem here actually? Please help me.