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
Today I was searching for the Retrofit interceptors on UA-cam especially for your channel, and what a coincidence, just got the notification 😅..
😊
us bro us 😍
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.
Awesome sir easy to understand waiting for next video😊
Thank you Nitin
Great explanation.
Can you please create a video or explain how we can navigate user to Login screen upon token expired/invalid.
Thank you Sir, Making this awasome video..You are great man ❤️❤️
Thanks and welcome
sir, your explanation is very good,keep it and make more and more videos on kotlin.Thank you sir
Thank you, I will
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
Sabse subscribe bhi karwa do 😂
Sure sabko laptop and mobile dono se subscribe karva lunga 😂😂
Great tutorial Sir, Please add one video related to auto refresh token when expired and continue with requested API call.
Great explained! Can you please explain how to pass dynamic BASE urls using hilt, in this video BaseUrl is static?
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...
That interceptor will automatically refresh token after it will expire . or we have to hit server again to refresh token ???
We have to manage...
Nice explane..but why not use base fragment...every time you need override the oncreate method that is not required..
Yes... already bahot badi series hogayi hai...we can certainly define one base fragment and have common methods inside it
Very nice explanation.
Please make a video on Leak Canary.
Sure I will
This code works over http not over https, how to automatically trust the host and certificate?
Sir How many videos are remaining in this series?
2 will be sufficient but let's see
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
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);
@@CheezyCode phir full url @url annotation me pass kru to same full url retrofit ke base url me dalna pdega
Base url won't be used in this case.. check the scrapping video
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?
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.
@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! 🙇🏻♀️
hii sir very nice explanations but what if we have more than one haeders like Content-type - application/json
Add it via interceptor only
amajing advice
Thanks
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?
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
Thank you sir.
Thank you to you too...
Is it true ...
I can earn 1 lakh rs/month from freelancing websites by doing android .. 🤔
True but requires hardwork...easy nahi h freelancing se kaam uthana
shukriya bhai
Thank you Uno
Thanks
Welcome
Where is the English version?!
If anyone want to learn latest Android code watch vlog of cheeze code.
Tutorial ❤️
@@CheezyCode ok sir.
#awesome sir...
❤️