Android Retrofit Interceptors + OkHttpClient | CheezyCode (Hindi)

Поділитися
Вставка
  • Опубліковано 15 жов 2024
  • Android Tutorial For Beginners - Learn how to use interceptors for passing dynamic header values with every request. Retrofit uses OkHttp behind the scenes. We need to create OkHttpClient to add interceptors. These interceptors help in adding headers to every request or you can add logging for every request using these interceptors. Interceptor is a powerful way to add dynamic values to your request object. Learn how to implement AuthInterceptor and OkHttpClient in this video.
    Learn how to implement Retrofit object with OkHttpClient along with HILT. This video clearly explains how to define Network Module for HILT. How to define different functions inside your module to provide you both Authenticated and UnAuthenticated flow. Learn step by step - how to create a fully functional android app with simple example in Hindi.
    Topics covered -
    1. What is Interceptor in Retrofit?
    2. How to implement Interceptor for Authentication Headers?
    3. How to pass tokens in every request in retrofit android.
    4. Create OkHttpClient and use it to create Retrofit Object
    5. Implement all this using HILT
    6. Complete Notes Android App Tutorial Hindi
    Complete Dependency Injection Playlist Link -
    • Dagger 2 - Dependency ...
    Complete Android Architecture Components Playlist -
    • Android Architecture C...
    Beginner series in Android Playlist (Hindi) -
    • Android Tutorials Step...
    Kotlin Beginners Tutorial Series -
    • Kotlin Beginner Tutori...
    For more info - visit the below link
    www.cheezycode.com
    Source Code -
    github.com/Che...
    We are social. Follow us at -
    Facebook - / cheezycode
    Twitter - / cheezycode
    Instagram - / cheezycode

КОМЕНТАРІ • 54

  • @nayannit
    @nayannit 2 роки тому +3

    Today I was searching for the Retrofit interceptors on UA-cam especially for your channel, and what a coincidence, just got the notification 😅..

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

    your explanation is amazing, Easy to understand . And Learn from your videos audience should have basic android development knowledge @cheexy code . Your channel as like a fast learning platform, over all thing done well.

  • @nitinbochare301
    @nitinbochare301 2 роки тому

    Awesome sir easy to understand waiting for next video😊

  • @yonija007
    @yonija007 10 місяців тому

    Great explanation.
    Can you please create a video or explain how we can navigate user to Login screen upon token expired/invalid.

  • @sunilmane2994
    @sunilmane2994 2 роки тому

    Thank you Sir, Making this awasome video..You are great man ❤️❤️

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

    sir, your explanation is very good,keep it and make more and more videos on kotlin.Thank you sir

  • @bhavyashah7052
    @bhavyashah7052 2 роки тому

    In our android team we have 50+ developers who work in large projects of kotlin and use your videos as reference plz cover with all maximum details as soon as possible

    • @CheezyCode
      @CheezyCode  2 роки тому +1

      Sabse subscribe bhi karwa do 😂

    • @bhavyashah7052
      @bhavyashah7052 2 роки тому

      Sure sabko laptop and mobile dono se subscribe karva lunga 😂😂

  • @chunilalgamit5369
    @chunilalgamit5369 2 роки тому

    Great tutorial Sir, Please add one video related to auto refresh token when expired and continue with requested API call.

  • @mandeepbhalothia7626
    @mandeepbhalothia7626 2 роки тому

    Great explained! Can you please explain how to pass dynamic BASE urls using hilt, in this video BaseUrl is static?

    • @CheezyCode
      @CheezyCode  2 роки тому

      Thanks 👍...we will create a separate tutorial for that...you can write a logic to separate these via build config...for dev you can use different url and for prod different url...

  • @Adnankhan-dq9rx
    @Adnankhan-dq9rx 2 роки тому

    That interceptor will automatically refresh token after it will expire . or we have to hit server again to refresh token ???

  • @mrdeveloper4438
    @mrdeveloper4438 2 роки тому

    Nice explane..but why not use base fragment...every time you need override the oncreate method that is not required..

    • @CheezyCode
      @CheezyCode  2 роки тому +1

      Yes... already bahot badi series hogayi hai...we can certainly define one base fragment and have common methods inside it

  • @pramodkumar-zc8et
    @pramodkumar-zc8et 2 роки тому

    Very nice explanation.
    Please make a video on Leak Canary.

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

    This code works over http not over https, how to automatically trust the host and certificate?

  • @Sound_Of_Arpit
    @Sound_Of_Arpit 2 роки тому +1

    Sir How many videos are remaining in this series?

    • @CheezyCode
      @CheezyCode  2 роки тому

      2 will be sufficient but let's see

  • @codetheandroid
    @codetheandroid 2 роки тому

    12:35
    bro is point pe aapne jo chij kri h same chij maine kri ek response test krne ke liye pr meri app phle crash hori h aur error deri h : E/AndroidRuntime: FATAL EXCEPTION: DefaultDispatcher-worker-1
    aur bro ek doubt tha maine kuch machine learning model ki api build kri thi azure cognitive service ka use krke to usne mujhe bnane ke baad ek url diya prediction ka aur kuch bhi nhi diye na end points vgera to ab m agr api interpace me only '/' likh ra hu to bhi error ari h .
    pr agr same url endpoint me derha hu to app ek bar crash kr ri h aur upr vali error deri h aur fir dubar run krra hu to reponse return kr ri h pr phir kbhi app dubara open kru to fir se error

    • @CheezyCode
      @CheezyCode  2 роки тому

      1. Use try catch - kuch error aa rahi h api hit karne pe
      2. @Url annotation ka use karo - full url pass karna padega iss case. E.g.
      @GET
      suspend fun methodName(@Url String url);

    • @codetheandroid
      @codetheandroid 2 роки тому

      @@CheezyCode phir full url @url annotation me pass kru to same full url retrofit ke base url me dalna pdega

    • @CheezyCode
      @CheezyCode  2 роки тому +1

      Base url won't be used in this case.. check the scrapping video

  • @samridhikotnala4958
    @samridhikotnala4958 2 роки тому

    Sir for login I need to pass a tenant type and then after that I have my normal APIs that require Autorization header. So should I pass both of them in a single interceptor or different interceptors are needed?

    • @CheezyCode
      @CheezyCode  2 роки тому

      2 calls hai ye 1 call mei 2 info bhejni h?
      if 2 calls hai then you can add it directly in your first api call and then use this interceptor in second call for authorization. Tenant type will be required only once I guess. No need to create interceptor for that.

    • @samridhikotnala4958
      @samridhikotnala4958 2 роки тому +1

      @Cheezy Code Yes sir 2 calls hai. Ok sir I will try to implement it.
      Thank you so much for this playlist and replying to each and every comment on every video on time! 🙇🏻‍♀️

  • @androidsurfers7572
    @androidsurfers7572 2 роки тому

    hii sir very nice explanations but what if we have more than one haeders like Content-type - application/json

    • @CheezyCode
      @CheezyCode  2 роки тому

      Add it via interceptor only

  • @mdjafarhamadhamad6509
    @mdjafarhamadhamad6509 2 роки тому

    amajing advice

  • @daxaparmar373
    @daxaparmar373 2 роки тому

    Hi, I'm working on a project which has 100+ api calls and I'm using retrofit...so in my retrofit interface I want to define generic methods for @POST, @GET, @PUT methods.
    Im providing endpoint dynamically and request as "Any" type and return type as "Response". But Retrofit doesn't parse body to dynamic type T.
    So, How can I use generic with retrofit interface?

    • @CheezyCode
      @CheezyCode  2 роки тому +1

      Refer this solution -
      stackoverflow.com/a/43935291
      Another solution could be having a wrapper api that internally calls your endpoint on server. You will just the call one method with all the data

  • @kushal7966
    @kushal7966 2 роки тому

    Thank you sir.

  • @Now_I_am_all_fired_up
    @Now_I_am_all_fired_up 2 роки тому +1

    Is it true ...
    I can earn 1 lakh rs/month from freelancing websites by doing android .. 🤔

    • @CheezyCode
      @CheezyCode  2 роки тому

      True but requires hardwork...easy nahi h freelancing se kaam uthana

  • @TheAqib57
    @TheAqib57 2 роки тому

    shukriya bhai

  • @AkashJhaDDN
    @AkashJhaDDN 2 роки тому

    Thanks

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

    Where is the English version?!

  • @YtFunVideos1-n4t
    @YtFunVideos1-n4t 2 роки тому

    If anyone want to learn latest Android code watch vlog of cheeze code.

  • @rishikeshsingh9946
    @rishikeshsingh9946 2 роки тому

    #awesome sir...