In this video series we will learn how to use Retrofit, which is a type-safe HTTP client for Android and Java.
Retrofit allows easy communication with a web service by abstracting the HTTP API into a Java interface.
In part 1 we will set up Retrofit in a new Android Studio project by adding the necessary Gradle dependencies, and then already do our first GET request.
We create an interface with 1 method that we annotate with @GET and the relative URL to the API endpoint of the REST API we want to query. We then create a Retrofit instance, define the baseUrl, add GSON as the converter by passing GsonConverterFactory to the addConverterFactory method, and let Retrofit create the implementation of our API interface at compile time.
The Call object that our GET method returns encapsulates a single request + response. With enqueue we can execute this request asynchcronously on a background thread and get our result back in the onResponse callback. OnFailure will be called if something in the process of communicating with the server or processing the response went wrong. With isSuccessFull we check if our response code is between 200 and 300 and if that’s the case we can retrieve our result from the response body.
GSON will parse the array of JSON objects into a List of the Java model class that we prepared beforehand.
Watch the whole playlist:
Example code, links & dependencies:
____________________
❗ Subscribe to the channel:
🎓 Find more tutorials and courses on my website:
💻 Hire me for your next project:
📨 Subscribe to the Coding in Flow newsletter:
💚 Donate to Coding in Flow with a message:
❓ Ask your programming questions in our chat:
📣 Follow Coding in Flow on other sites:
Facebook:
Instagram:
Twitter:
Github:
⌨️ My gear and tools:
Microphone:
Mouse:
Keyboard:
Desk:
Monitor:
Webcam:
Screen recorder:
(above links are affiliate links, which means that I earn a small commission if you buy through them with NO additional costs to you.)
retrofit, retrofit android, android retrofit, android retrofit tutorial, android retrofit 2 tutorial, android retrofit json example, android retrofit vs volley, android retrofit2 example, android retrofit tutorial for beginners, retrofit android tutorial to get json from server, retrofit 2 android tutorial, android retrofit tutorial 2018, retrofit android example tutorial, retrofit 2.0 android tutorial, retrofit get, retrofit get request, android get request, volley, networking
Xem Thêm Bài Viết Về Mobile Khác: https://sealsystem.org/mobile
Nguồn: https://sealsystem.org/
does anyone know how to enable auto import like he did? 6:21, he just put serializedname then android studio auto imports them up top. i ve already setup settings in auto imports and check all of it.
This project use main thread . right???
Thank for such a simple and good explanation
ty <3
Are you from germany?
CLEARTEXT communication to jsonplaceholder.typicode.com not permitted by network security policy
hai, how can i auto fetch the data from server?
Thank u so much for all the work u do.
I have a question, can u please make tutorial of "How to get json data from multiple urls in one activity'
Thank u sir
hey it says: ERROR: Failed to resolve: okhttp
Affected Modules: app
what do i do 🙁
THANK YOU SOOOO MUCH GREAT VIDEO
EXPLAINED SIMPLY
cool.. and this video explains how to simply secure the api to the endpoint https://www.youtube.com/watch?v=s6A_oJkJbgc
I can change the URL with my own Database?
Great Work bro!!
Guide is old. Factory class doesn't exist at .addConverterFactory.
I really like that you kept this simple by focusing of the thing that matter
I get an error unable to parse TLS packet
is Retrofit library royalty free ?
would you suggest retrofit or volley?
why one over the other?
thank you
java.lang.BootstrapMethodError: Exception from call site #4 bootstrap method
I got this error 😥😪
I was watching this video on your personal website but I couldn't resist coming here and liking this video here
can you give a link
This video helped me to understand… Explaination is very nice… Thank you!!
انت عربى؟؟
i love ur tutorial thank you sir
awesome
Damn bro your tutorials are really good. The zooms and the clarity of the explanation 💯 Keep up the good work man!
Danke Florian!
THANK YOU
Thanks bro, this was a very clear and useful expalantion
Thank you so much, great explanation… and nice accent ^^
thanks for sharing
Can please any one help me how to convert the json data into geojson ?
Again YOU bro, gonna learn retrofit with java, thank you all things that you taught to me in java and android studio