0

I searched stack overflow for the answer but never find one, I'm curious why we define endpoint, request method in short a request for the server in the form of interface, what is the benefit of defining request as interface

Thanks in advance

1
  • 1
    I think Interface is enough for annotation processing. To determine what kind of request Retrofit class should make.
    – Son Tieu
    Nov 11, 2017 at 17:38

1 Answer 1

2

For the simply reason that defining an interface is more easy than implementing it.

Retrofit is dead-simple to use. It essentially lets you treat API calls as simple Java method calls

With Retrofit you describe the endpoint that you want to consume as a basic java interface and retrofit will build a type safe implementation of your interface at compile time.

Here you can find a very good guide to Retrofit 1.9 and 2 and here there is a nice podcast that talks about Retrofit and OkHttp.

3
  • so its internal to retrofit that how it implementing and using it? Nov 11, 2017 at 17:55
  • yes, it's internal to retrofit but you can change some behaviors, example which http client you want to use (apache httpclient, okhttp), which json converter (jakson, gson), etc, etc.
    – db80
    Nov 11, 2017 at 17:58
  • 1
    thank you for such a simple answer. I also was wondering this but glad to see it literally is DEAD simple.
    – reidisaki
    May 10, 2018 at 4:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.