Conclusion
This lesson guided you through adding Kotlin coroutines into your networking code. You’ve learned how Retrofit seamlessly integrates with Kotlin coroutines to make your code simple, readable, and maintainable. The key takeaways from this lesson are:
— Retrofit supports Kotlin coroutines out of the box.
— Marking Retrofit interface methods with suspend gives you Retrofit-related code generated for
you that also handles threading.
— You can return your custom types directly or wrap them with Response<T> if you need the
response metadata.
— Error handling is done natively with try/catch or runCatching.
— You get a nice syntax in the calling code by using onSuccess and onFailure
extension functions on Result.
In the next lesson, you’ll learn about Interceptors and authentication with Retrofit. You’ll
also implement the two remaining methods in MovieDiaryApi.kt — getProfile() and postReview(). See
you there.
:]