Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Yes, there is a way to add headers to a Retrofit API request without using an Interceptor. You can add headers directly to the method or the request using the @Headers annotation in Retrofit.

For example:

@Headers("Authorization: token123")
@GET("user")
Call<User> getUser();

This will add an "Authorization" header with the value "token123" to the GET request for the "user" endpoint.

You can also add multiple headers using the @Headers annotation with multiple values:

@Headers({
    "Authorization: token123",
    "Accept: application/json"
})
@GET("user")
Call<User> getUser();

This will add both "Authorization" and "Accept" headers to the GET request.