Ktorfit icon indicating copy to clipboard operation
Ktorfit copied to clipboard

Set the Headers value as vararg

Open DatL4g opened this issue 1 year ago • 0 comments

Is your feature request related to a problem? Please describe.

Not a real problem, however in Retrofit it's possible to call Headers like this (with a single value):

@Headers("Accept: application/json")
@GET
fun example(): Call<Example>

In Ktorfit an Array is required:

@Headers(["Accept: application/json"])
@GET
fun example(): Call<Example>

Describe the solution you'd like

It's not much of a deal, but if the Headers value would be a vararg, it could be used like in Retrofit.

Instead of:

@Target(AnnotationTarget.FUNCTION)
annotation class Headers(val value: Array<String>)

Change it to this:

@Target(AnnotationTarget.FUNCTION)
annotation class Headers(vararg val value: String)

Additional context

Changing the type to a vararg comes with one "disadvantage" The Headers would be set like this if you have multiple values:

@Headers("Accept: application/json", "Content-Type: application/json")
@GET
fun example(): Call<Example>

The current configuration looks like this:

@Headers(["Accept: application/json", "Content-Type: application/json"])
@GET
fun example(): Call<Example>

DatL4g avatar Aug 11 '22 17:08 DatL4g