I'm new to programming in Java and try to understand how annotations works in big libraries.
Can someone show me code snippet in which retrofit is actually processing the functions annotations from the API service interface that I pass as the argument to retrofit.create method and change its behavior based on this? I mean: @GET, @POST etc
I created the interface Giphy Api Service with next function:
@GET("gifs/search")
fun getSearchedGifs(
@Query("q") searchTerm: String,
@Query("limit") limit: Int = 50,
@Query("offset") offset: Int = 0,
@Query("rating") rating: String = "g",
@Query("lang") lang: String = "en",
@Query("bundle") bundle: String = "messaging_non_clips",
@Query("api_key") apiKey: String = "my api key"
): Call<DataResult>
this function have @GET("gifs/search") which represent the HTTP GET request.
Then I use this interface to create instance of retrofit object in the next code:
val retroService = retrofit.create(GiphyApiService::class.java)
I checked retrofit.create() method and all file, but do not find answer to my question
Retrofit2 uses a dynamic proxy to make an interface implementation instead of the code generation.
It parses your methods with the refletion, makes SeriveMethod
of methods and caches them into serviceMethodCache
.
When you invoke a method of your interface, a created ServiceMethod
will be invoked instead.