Retrofit Tutorial Part 1 – SIMPLE GET REQUEST – Android Studio Tutorial

33
1



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/

33 COMMENTS

  1. 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here