Retrofit - Send a simple GET Request | Android Studio Tutorial

  Рет қаралды 97,953

Stevdza-San

Stevdza-San

Күн бұрын

🏆 My Online Courses
⭐Discount Coupon: LAUNCH-STEVDZA-SAN
stevdza-san.com
🐱‍👤 Wanna become a member? Join!
/ @stevdzasan
📸 Instagram
/ stevdza_san
Retrofit is a Type Safe REST client for Android Developed by square. It uses okHttp library for HTTP requests, and it's one of the best tools for performing network requests in android applications. In this video I'll show you how to send a simple GET request, receive a result in JSON, convert it to Kotlin object and display it back in our app. So with this video I'm starting a new short tutorial series about Retrofit library, so stay tuned!
Retrofit requires three main components:
1. Retrofit Instance:
We can create an instance of Retrofit by Retrofit.Builder class. And we have to specify the base url and converter factory at the time of the Retrofit instance creation
2. Model Class:
Retrofit needs a Model class for sending and receiving Request. It uses the model class for parsing server Response by using converters like Gson, Moshi etc.
3. An Interface for possible API calls:
The interface contains methods that represents possible API calls. Each methods need a base Url end point annotation that represents the Http methods like GET, POST etc.
Timestamps:
0:00 - Introduction
1:12 - Create Model class
2:28 - Create SimpleApi interface
3:15 - Create Constants class
3:53 - Create RetrofitInstance object (Singleton)
5:02 - Create Repository
5:43 - Create MainViewModel class
6:46 - Create MainViewModelFactory class
7:25 - Implement the logic
9:29 - Handle Exceptions

Пікірлер: 153
@sebbytrial
@sebbytrial 3 жыл бұрын
This video is GOLD. Came only for Retrofit, left with much more.
@stupidfilip23
@stupidfilip23 3 жыл бұрын
It's actually not, because you don't understand why he did it, you can just copy the steps and that's not good teaching
@irohwavez
@irohwavez 3 жыл бұрын
Finally, an API call example that is easy to follow and is structured in the proper way. Thank you.
@solomonayodeleo
@solomonayodeleo Жыл бұрын
Its 2023 and this tutorial is still serving well❤
@fb296
@fb296 4 жыл бұрын
Your channel and awesome videos made me start developing Android apps, thank you!
@kalibra2121
@kalibra2121 2 жыл бұрын
man...seriously... your content is amazing :| exactly on point, so simple explained.. so clean :) thank you! we really appreciate your work
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Thank you Vlad, I'm happy to hear that I helped. 😉
@mrandroid6764
@mrandroid6764 4 жыл бұрын
Your Tutorials are great....keep up the great work...love you
@pradeep9222
@pradeep9222 2 жыл бұрын
you make android intern's life easy and smooth, thank you again
@Waleed_Al-Haidary
@Waleed_Al-Haidary 4 жыл бұрын
Great tutorial, THANKS, looking forward to see the next tutorial/s
@GameWorkflow
@GameWorkflow 3 жыл бұрын
Really helpful video. Really like the way you structure things
@pushpendratripathi46
@pushpendratripathi46 4 жыл бұрын
Awesome tutorial. Thanks for this tutorial. Waiting for next one.
@emanuelalvarez2908
@emanuelalvarez2908 2 жыл бұрын
This was incredibly useful. Thank you.
@s4int812
@s4int812 4 жыл бұрын
Great tutorial Waiting for next one👌😁
@FarrukhSaliev
@FarrukhSaliev 3 жыл бұрын
Amazing tutorial as always! 😊 I like your channel.
@AndreaDeGaetanoDotCom
@AndreaDeGaetanoDotCom 2 жыл бұрын
Well done! the only thing I want to suggest is to use another name for the model you are using: Post is easy to confuse with Http/Post. the rest is great!
@wilsonahanmisi1187
@wilsonahanmisi1187 3 жыл бұрын
This is just beautiful..... Thanks Bro
@dimensions-xyz
@dimensions-xyz 2 жыл бұрын
Thanks. It was a really understandable training video!
@mohammadatif2774
@mohammadatif2774 3 жыл бұрын
Wow ... clear and consice !!
@gunther982
@gunther982 3 жыл бұрын
i have an URL with xml content on it. I want to GET the xml data every time I start my activity. Then I want to present certain parts of the data in my app. How should I go about this?
@abrarwiryawan
@abrarwiryawan 3 жыл бұрын
Amazing tutorial
@brucebane7401
@brucebane7401 3 жыл бұрын
AMAZING !!!!
@andreaf4861
@andreaf4861 3 жыл бұрын
thanks for the video, helped a lot man
@daiyrkanybekov8575
@daiyrkanybekov8575 3 жыл бұрын
Good tutorial Bro!!
@prasannadeshpande4435
@prasannadeshpande4435 Жыл бұрын
You make really great videos.
@prometheusli101
@prometheusli101 3 жыл бұрын
thanks!!awesome course
@yurii_s_m_25
@yurii_s_m_25 3 жыл бұрын
Thanks. Great example
@bakjoul
@bakjoul 3 жыл бұрын
This tutorial is very well done. Too bad i didn't understand much. This seems so complicated for something supposed to be simple. But it works great !
@Spham99
@Spham99 2 жыл бұрын
lollll same
@lyawileh.a8741
@lyawileh.a8741 2 жыл бұрын
I hope you understood it after a number of replays.
@miltongua
@miltongua Жыл бұрын
50 new files, 300 new lines just to make a get request omg
@denisdominguez7287
@denisdominguez7287 3 жыл бұрын
Awesome!!!! ♥♥♥
@AlessandroMariucciConsulting
@AlessandroMariucciConsulting 3 жыл бұрын
Ciao Stvdza, thanks a lot for the video! How should I handle a SocketTimeoutException error (the App keeps crushing in that case)?
@user-os8zr3sd2m
@user-os8zr3sd2m 3 жыл бұрын
good explanation of the material
@limo1175
@limo1175 2 жыл бұрын
thank ,help me a lot
@Hrit
@Hrit 2 жыл бұрын
What a Solid Explanation!
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Thanks 🚀
@marcinbiaecki9731
@marcinbiaecki9731 3 жыл бұрын
Thank you! :)
@federicomoreiratejera4478
@federicomoreiratejera4478 2 жыл бұрын
Your videos are very good and very useful. I would love for you to show examples of delete and update with retrofit, it would be very helpful. Thank you so much
@user-qb6ct2im7z
@user-qb6ct2im7z 2 жыл бұрын
how did you access the TextView directly in MainActivity?
@alejandromorales1324
@alejandromorales1324 3 жыл бұрын
Hey bro when executing the app it closes automatically and does not consume the api, but does not show any error
@brucebane7401
@brucebane7401 3 жыл бұрын
when we say private retrofit by lazy dont we have to specify the datatype like private val :className by lazy what exactly is that supposed to mean
@ubedkhorajiya4144
@ubedkhorajiya4144 2 жыл бұрын
Thanks!
@alexsibiya8873
@alexsibiya8873 4 жыл бұрын
Great 👌, I have a question about to how use GET to search published articles in your personal website that u loaded in a webview using searchview
@user-cm8yx7xd7f
@user-cm8yx7xd7f Жыл бұрын
The way you provide the dependencies through a pattern is it called MVC or MVP ?
@krix5623
@krix5623 2 жыл бұрын
It's crazy how you need 5 files for a simple get request, which you can do in 10 lines in JavaScript
@olehmazur6412
@olehmazur6412 2 жыл бұрын
Same thoughts. Why complicate simple things !?
@OCEH6
@OCEH6 2 жыл бұрын
In android dev this example is very good. 5 files need to make app with SOLID principles and easy to understand, service and extend. In youtube it rare video there author use architect principles. It is a best way. And yes android dev (Kotlin/Java) is very different from other devs. Knowledge of language is a micro bit of required hard skills. To make normal (not good or awesome app) need know many things: life cycle of activity, lifecycle of fragments, permissions, data store, UI/UX, databases,multi treading and much more. And u can make one gold file with all logic but it worst way. It garanty memory leak, unstable, lose data and bad user experience.
@EnsYlmaz51
@EnsYlmaz51 3 жыл бұрын
can we use interfaces instead of classes for response?
@androidmillennium9266
@androidmillennium9266 2 жыл бұрын
Thanks a lot
@muhohojeremy4861
@muhohojeremy4861 2 жыл бұрын
How can retrofit get api callbacks for example in my case I am doing back end validation with laravel "email": [ "The email field is required." ], "password": [ "The password field is required." ], "device_name": [ "The device name field is required." ] How do I consume this with retrofit to show the relevant error messages.
@Kmaangaty
@Kmaangaty 3 жыл бұрын
hi i have a problem when i call the api for first time it work but if i clicked the button for second time it make 2 calls what is wrong
@Samson.CodeArchive
@Samson.CodeArchive 2 жыл бұрын
thank you for this content
@StevdzaSan
@StevdzaSan 2 жыл бұрын
You're welcome 👊
@angelmauriciorivas6160
@angelmauriciorivas6160 3 жыл бұрын
Muchas Gracias Sensei
@aranyaprakash5537
@aranyaprakash5537 3 жыл бұрын
Damn this is a coding style I can aspire for
@Jetbalance4
@Jetbalance4 2 жыл бұрын
Hi! Help me, please! How should I catch the "no internet connection" error?
@Akram_El-Masry
@Akram_El-Masry 3 жыл бұрын
thank you a lot
@ubedkhorajiya4144
@ubedkhorajiya4144 2 жыл бұрын
Mutable live data trigger so many time i got wrong response how can fix
@TamFbs
@TamFbs 3 жыл бұрын
Very nice
@zakwanibrahim7283
@zakwanibrahim7283 Жыл бұрын
Hello ... is this architecture is MVVM?
@ilhamaliyudin4779
@ilhamaliyudin4779 3 жыл бұрын
how to handle SocketTimeOut masterrr??
@salvadorduenas4183
@salvadorduenas4183 2 жыл бұрын
Thank your code is very easy
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Thanks buddy 👍
@ismailkassim6325
@ismailkassim6325 4 жыл бұрын
Does the order of the variables matter when parsing Jason?
@ramazankoldas8061
@ramazankoldas8061 2 жыл бұрын
hayır
@Hobynist
@Hobynist 8 ай бұрын
Hi! Thanks for the video. That maybe simple in Jetpack Compose but compare that to other libraries (for example with React Native) i´ve used that´s not simple at all 😄
@henrygalvan9333
@henrygalvan9333 2 жыл бұрын
@Stevdza-San I am currently using jetpack compose, does this mean I do not longer need view model factory ?
@StevdzaSan
@StevdzaSan 2 жыл бұрын
I haven't used ViewModelFactory in a while. Becuase I'm using Dagger-Hilt to inject all my ViewModels directly.
@henrygalvan9333
@henrygalvan9333 2 жыл бұрын
I still need to learn Dagger-Hilt and the importants of injection. I am so behind sadly. Thank you for your knowledge 🙏
@henrygalvan9333
@henrygalvan9333 2 жыл бұрын
Hey stevdza! I just recently relized in your udemy ToDo app course . Which i own. You explain how to use dagger hilt and just like you mentioned in this messege. You use dagger hilt to inject all your view model directly. And that is exclacly what i will learn in your udemy course. Correct?
@StevdzaSan
@StevdzaSan 2 жыл бұрын
@@henrygalvan9333 Correct ✅
@mohamadkh221
@mohamadkh221 3 жыл бұрын
thank u
@ivansanchezmartinez8941
@ivansanchezmartinez8941 2 жыл бұрын
8:50, I get the word "Observer" in gray and I don't know why (Line 22). If someone can help me, because the program does not work for me and I suspect that is why.
@OCEH6
@OCEH6 2 жыл бұрын
Hi do u still need help?
@MrRahulmalik
@MrRahulmalik 4 жыл бұрын
Please make a video on how to consume GraphQl api with Apollo using MVVM and coroutines with repository pattern
@JoseCastillo-df5xw
@JoseCastillo-df5xw 4 ай бұрын
2024 and this video save my life
@JoseCastillo-df5xw
@JoseCastillo-df5xw 4 ай бұрын
Guys if anny watch this video in 2024 , two things for fix : in the final textView.text u need declare dis var : val textView: TextView = findViewById(R.id.TextView) ; and if u have a error here, verify ur main_activity.xlm and check if ur TextView have the id : TextView.
@joinnownow7788
@joinnownow7788 3 жыл бұрын
How to send specific data?
@MrLOLs1
@MrLOLs1 4 жыл бұрын
Thx
@OCEH6
@OCEH6 2 жыл бұрын
Awesome! Thank you a lot!
@klekaelly
@klekaelly 2 жыл бұрын
So I was using this as a guide for interfacing with a different API. Does my data class need to represent the API's response exactly? In other words, can I leave out a few data points that I don't care about that is being returned from the API?
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Yeah sure you can. :)
@ahmedshukri1752
@ahmedshukri1752 3 жыл бұрын
I get this error : *Unable to create call adapter for class java.lang.Object*
@ayyashexe6524
@ayyashexe6524 Жыл бұрын
if you solved it please tell me how ^^
@jonasivy
@jonasivy 3 жыл бұрын
Interface Lazy does not have constructors
@abdifatahmohamed8600
@abdifatahmohamed8600 3 жыл бұрын
Hello sir... You might have seen me in most comments. Sincerely this channel is crazy nice. I lost count of how many developers I've shared the link with. Thanks bro. Would you mind doing retrofit with progress bars when uploading/downloading data?
@stevenalexander6262
@stevenalexander6262 2 жыл бұрын
amazing video but so confused on how the folder structure works, or how they're all connected to each other. There's also no reason given for all these folders, classes and instances made, literal copy and paste. Like why are you bouncing a method call 5 times? I don't even know where the code ends up to at that point
@arpitgupta3151
@arpitgupta3151 3 жыл бұрын
I'm getting E/AndroidRuntime: FATAL EXCEPTION: main error
@firuzaaliyeva5382
@firuzaaliyeva5382 3 жыл бұрын
I get the same exception, could you find solution?
@nirajgusain1452
@nirajgusain1452 3 жыл бұрын
@@firuzaaliyeva5382 compileOptions{ sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } //add these lines in build.gradle
@tahermadras5371
@tahermadras5371 2 жыл бұрын
how to get multiple posts
@omidphoenix4883
@omidphoenix4883 4 жыл бұрын
Thanks it would be more helpful if you could lower the pace of your great tutorials
@ultimategolfarchives4746
@ultimategolfarchives4746 Жыл бұрын
Totally. "Write this, because this is how it works" doesn't explain much....
@ronneyismael605
@ronneyismael605 3 жыл бұрын
Please make videos on restful api. how we are making APIs.
@scottbiggs8894
@scottbiggs8894 3 жыл бұрын
Very informative, but so fast!!! I had to pause the video a dozens of times just to blink.
@vedx
@vedx 4 жыл бұрын
Great explanation 👌. And can you make tutorial on paging library.
@StevdzaSan
@StevdzaSan 4 жыл бұрын
Yes there will be a video about it in the future.
@alirezabashi98
@alirezabashi98 3 жыл бұрын
😍😍😍😍😍😍😍😍😍
@cioccari11
@cioccari11 3 жыл бұрын
Thanks for that tutorial bro, it helped me a lot. Now I'm trying to get data from an API de returns an Array of Objects, instead of an Object, but I can't solve this problem and the GSon's User Guide didn't help me so much, could you or somebody else help me with that?
@ilhamaliyudin4779
@ilhamaliyudin4779 3 жыл бұрын
Me too. Have u got a solutions??
@cioccari11
@cioccari11 3 жыл бұрын
@@ilhamaliyudin4779 Unfortunately I haven't found any solution, I ended up using another API :( But if anyone could help with it would still be great
@anmolsharma9539
@anmolsharma9539 3 жыл бұрын
You got solution ?? I am trying to fetch data from zomato api but i am confused as if i call it as shown above it will only give 1 restraunt data
@archunanr1068
@archunanr1068 3 жыл бұрын
viewModelScope does not work also i add the library can you help me to fix it please
@arielasbelherasmeperez6553
@arielasbelherasmeperez6553 3 жыл бұрын
Add this line in your build.gradle(:app): implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0"
@radick16kytyax
@radick16kytyax 4 жыл бұрын
Hello, I like your tutorials so much! You helped me with SQL dataBase!)) I have an Idea for you could you make a video -How to make database using TXT file Only- We have 2 textViews (Word, Translation) and 1 button (Randomizer) which randomizes them
@joinnownow7788
@joinnownow7788 3 жыл бұрын
Suddenly stop on android 4.
@user-cm8yx7xd7f
@user-cm8yx7xd7f Жыл бұрын
Why to use !!
@user-cm8yx7xd7f
@user-cm8yx7xd7f Жыл бұрын
why not use var?.let{ //code}
@pyaesonehan19
@pyaesonehan19 2 ай бұрын
@HyperActive94
@HyperActive94 4 жыл бұрын
please show us how to use @GET and @POST with the SketchFab API. please please please :)
@saharmohammadi2421
@saharmohammadi2421 3 жыл бұрын
Could you please share the files of this project? Thank you
@jankastbjerg4017
@jankastbjerg4017 2 жыл бұрын
awesome tutorial, but holy hell you talk and type fast xD
@StevdzaSan
@StevdzaSan 2 жыл бұрын
I'm learning not to talk that fast 😄
@jankastbjerg4017
@jankastbjerg4017 2 жыл бұрын
@@StevdzaSan but anyway, thx man, have been trying to figure out how to contact my restAPI for the last 2 days, and nothing worked, but 1 hour with your tutorials, and now it works like a charm! :)
@h.r.60
@h.r.60 4 жыл бұрын
😁
@Spham99
@Spham99 2 жыл бұрын
Could you provide the Github link to this project?
@michaelchristensen8350
@michaelchristensen8350 2 жыл бұрын
Hi I am a beginner. I like your content. I also bought some of your video on Udemy. But I really really wish you would slow down the pace. It is very hard to follow, you are going to fast man. Slow down, and explain things a bit more detailed, and your content would be even better :-)
@StevdzaSan
@StevdzaSan 2 жыл бұрын
Thanks for your suggestion 👍 😊
@joinnownow7788
@joinnownow7788 3 жыл бұрын
Got stopped android
@yasinozkurt
@yasinozkurt Жыл бұрын
Whats this mess? I mean why should we code this much to make a simple request?? Why cant we just call a function like request.get("url")?? I am fed up with android and its interfaces, templates, frames...
@joegoosebass3958
@joegoosebass3958 2 жыл бұрын
This is out of date
@esoldado7281
@esoldado7281 4 жыл бұрын
maaaaan , why Kotlin 😭 , anyways , thanks you a lot
@TheMrAntosiek
@TheMrAntosiek 2 жыл бұрын
class MainViewModelFactory(private val repository: Repository):ViewModelProvider.Factory { } throws me an error "Inheritance from an interface with '@JvmDefault' members is only allowed with -Xjvm-default option" what should i do?
@dimasfaiz2716
@dimasfaiz2716 Жыл бұрын
i stuck at the same problem, have you found the solution?
@TheMrAntosiek
@TheMrAntosiek Жыл бұрын
@@dimasfaiz2716 No
@alexredison
@alexredison 2 жыл бұрын
For anyone getting error message "Class 'ViewModelFactory' is not abstract and does not implement abstract member", remove nullability sign (?) in MainViewModelFactory.kt. Like this - override fun create(modelClass: Class): T {
@ubedkhorajiya4144
@ubedkhorajiya4144 2 жыл бұрын
Mutable live data trigger so many time i got wrong response how can fix
@ubedkhorajiya4144
@ubedkhorajiya4144 2 жыл бұрын
Mutable live data trigger so many time i got wrong response how can fix
@ubedkhorajiya4144
@ubedkhorajiya4144 2 жыл бұрын
Mutable live data trigger so many time i got wrong response how can fix
The Ultimate Retrofit Crash Course
34:49
Philipp Lackner
Рет қаралды 91 М.
Inside Out 2: Who is the strongest? Joy vs Envy vs Anger #shorts #animation
00:22
No empty
00:35
Mamasoboliha
Рет қаралды 10 МЛН
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 22 МЛН
Best KFC Homemade For My Son #cooking #shorts
00:58
BANKII
Рет қаралды 72 МЛН
ROOM Database - #1 Create Database Schema | Android Studio Tutorial
14:59
Retrofit - Send a simple POST Request | Android Studio Tutorial
9:12
Navigation Component - Android Studio Tutorial
12:11
Stevdza-San
Рет қаралды 172 М.
Deep Dive into REST API Design and Implementation Best Practices
12:02
Software Developer Diaries
Рет қаралды 44 М.
LiveData Explained - Android Architecture Component | Tutorial
12:12
News App in Android Studio using Kotlin | Part 4 - Adapter & Repository
21:04
Inside Out 2: Who is the strongest? Joy vs Envy vs Anger #shorts #animation
00:22