1
Answer

How to append Headers in Retrofit API call without using Interceptor

Ravikant Sahu

Ravikant Sahu

1y
703
1

I am using a base URL like below

private const val BASE_URL = "anyURL"

an htt*P client

private val client = OkHtttpClient.Builder().apply {
    addInterceptor(MyInterceptor())
}.build()

a retrofit client

private val retrofit = Retrofit.Builder()
    .addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
    .client(client)
    .baseUrl(BASE_URL).build()

and a get call

@GET("playlist_tracks=*********")
suspend fun geAlltracks(): Music

Currently, I am using an interceptor, but how can append my request with headers without Interceptor

Answers (1)