Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consuming Rest Api with retrofit in Android

Consuming Rest Api with retrofit in Android

consuming dog api with retrofit

ValentineRutto

May 08, 2021
Tweet

More Decks by ValentineRutto

Other Decks in Programming

Transcript

  1. API(application programming interface). It is a set of rules that

    allow programs to talk to each other. REST(“Representational State Transfer”) -Determines how the API looks like -It is a set of rules that developers follow when they create their API What is Rest API?
  2. A client library developed by square that is used to

    create HTTP Requests and process HTTP responses from a REST API Retrofit library
  3. • Retrofit Interface An interface that defines HTTP operations @GET("api/breeds/image/random")

    suspend fun getRandomDogImage(): DogImageResponse • Retrofit class Creates an instance of retrofit and implements the retrofit interface methods val apiClient: ApiService= Retrofit.Builder() .baseUrl("https://dog.ceo") .client(OkHttpClient()) .addConverterFactory(GsonConverterFactory.create()) .build() .create(ApiService::class.java) • Retrofit Converters Defines format that data will be represented in. GSON is JSON mapping. Retrofit Classes