Retrofit Android Tutorial for Beginners with Kotlin

Поділитися
Вставка
  • Опубліковано 7 лют 2025
  • Learn the basics of making API calls with one of the most popular HTTP clients for #android using #kotlin.
    Consider Subscribing 🤩
    / @danieltalkscode
    Retrofit: square.github....
    Moshi: github.com/squ...
    OKHttpInterceptor: github.com/squ...
    Wizard World API: github.com/Mos...
    JSON to Kotlin Plugin for Android Studio: plugins.jetbra...
    -----
    The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.

КОМЕНТАРІ • 22

  • @fixitman5453
    @fixitman5453 10 місяців тому +4

    EXACTLY what I was looking for! Thank you!

  • @benakin9172
    @benakin9172 3 місяці тому

    THANK YOU. You just helped me complete a similar take home test at the last minute. Everything is clear and concise and most importantly modern so I don't have to look far back. let's go!!

    • @danieltalkscode
      @danieltalkscode  3 місяці тому

      Thank you for the kind words! Glad the video was helpful 🙂

  • @MrACrazyHobo
    @MrACrazyHobo 4 місяці тому +1

    Thank you so much for using modern android technologies (ie jetpack compose)

  • @andrew7324
    @andrew7324 3 місяці тому

    Super, super helpful and really easy to follow.

  • @thanakornsrisuwan2498
    @thanakornsrisuwan2498 11 місяців тому +1

    Hello Daniel, Can you make tutorial from Rapid Api Please 🙏

  • @scottbiggs8894
    @scottbiggs8894 5 місяців тому

    After following the video, I keep getting crashes when I try to run at the 12:15 mark. From the logs, it looks like there's an infinite loop happening somewhere in the retrofit code. Anyone else? And is there anyway to see the actual code so I'll know I typed (and translated when the code was old, ie build.gradle) correctly?

    • @rodrigogarcia3904
      @rodrigogarcia3904 5 місяців тому

      I was getting an error about invoking viewModel() in the MainActivity, but it fixed after manually adding the import at the top of MainActivity. import androidx.lifecycle.viewmodel.compose.viewModel

  • @danielsgrunge
    @danielsgrunge 9 місяців тому

    Thank you so much fellow Daniel 😅

  • @giapxuan4208
    @giapxuan4208 9 місяців тому

    Nice. Thanks for all sir

  • @arjinkavalci172
    @arjinkavalci172 8 місяців тому

    Do we need to authorize first, if we want to make PUT operation?

    • @danieltalkscode
      @danieltalkscode  8 місяців тому

      Yes, typically you need to authorize to make a PUT http operation. This is because a PUT request is often used to update or replace a resource on a server, which can have significant implications for data integrity and security.

    • @arjinkavalci172
      @arjinkavalci172 8 місяців тому

      @@danieltalkscode thanks now i understand, but how can i authanticate on android side just like swagger? I heard that i should pass jwToken value as an header? Is it the correct way?

    • @danieltalkscode
      @danieltalkscode  8 місяців тому

      Sure! That's one of the common ways to authenticate. Save the JWT token in SharedPreferences after login, then use an OkHttp Interceptor with Retrofit to add the token to each request's header. This way, all requests will include the JWT for authentication.

    • @arjinkavalci172
      @arjinkavalci172 8 місяців тому

      @@danieltalkscode thank you for help, I can handle it now 🙏🏻

  • @jamaal1282
    @jamaal1282 Рік тому

    Hi could you add Unit Tests and espresso tests to the to do app please?

  • @kir4n
    @kir4n Місяць тому

    U said it is for beginners but can u at least explain whatever you are writing the code? the moshi and all that stuff, builder etc, u just kept writing, explaining nothing
    ]

    • @danieltalkscode
      @danieltalkscode  Місяць тому

      Hi there! 😊 Thanks for your feedback-I really appreciate it! Let me break down the code in the RetrofitClient and explain it step-by-step:
      1. Moshi is a library that helps convert JSON (data from the internet) into objects your app can use. For example, if the API sends data about wizards, Moshi helps turn that into a Kotlin object like `Wizard(name = "Harry", house = "Gryffindor")`. It’s very useful when working with APIs, and we add it to Retrofit to handle this conversion.
      2. HttpLoggingInterceptor: This helps me create a "logger" object. It’s a tool that logs (prints) all the API calls and responses to the console. This helps me debug by showing exactly what data is sent and received. For example, if something goes wrong, I can check the logs to see what the API returned.
      3. The RetrofitClient object from the 10:50 min mark in the video: This is like a translator for your app to talk to the API. It uses the base URL (`wizard-world-world.api.herokuapp.com`) to know where to send requests. The `.addConverterFactory()` tells it to use Moshi for handling JSON, and `.client(okHttpClient)` adds the logger so you can see the API details in your console.
      This setup lets your app fetch wizard data (or anything else) from the API and use it in your app! 🚀
      Lastly, I wanted to let you know that I’m shifting the channel’s focus to web development and other programming topics. I probably won’t make more Android tutorials, but I’m so glad this one was helpful to you!
      Thanks for watching and supporting the channel! 💻✨