Ravikant Sahu

Ravikant Sahu

  • Tech Writer
  • 6.7k
  • 289.7k

How to append Headers in Retrofit API call without using Interceptor

Mar 30 2023 5:45 AM

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)