As my APIs requests all contains some json fields in common, I would like to add those fields inside an interceptor, but I'm struggling to modify the OkHttp3 RequestBody inside the interceptor
Here is my retrofitBuilder:
private val retrofitBuilder by lazy {
val client = OkHttpClient.Builder().apply {
addInterceptor(MyInterceptor())
}.build()
Retrofit.Builder()
.baseUrl("https://placeholder.com/")
.addConverterFactory(GsonConverterFactory.create())
.client(client)
.build()
}
And here is the interceptor:
class MyInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
//Is it possible to change it in JSON? Or how do I add paramenters to this body?
val body: RequestBody? = chain.request().body()
return chain.proceed(chain.request())
}
}
How can I add, for example "traceId" : "abc123" to all my requests body inside the Interceptor?