user3860944
user3860944

Reputation: 39

about Retrofit get and post methods parameters

I read retrofit is good for client server communication.

In this I have some doubts.

@GET("/group/{id}/users")
List<User> groupList(@Path("id") int groupId);

In get method what is group, id, users, and what is groupList(@Path("id") int groupId). What will it do exactly?

Upvotes: 1

Views: 156

Answers (2)

nikis
nikis

Reputation: 11254

When you build a new adapter for your interface with Retrofit you specify some server as endpoint. Let's say your endpoint is http://www.example.com. After that, when you execute groupList method, Retrofit will send a GET request to the http://www.example.com/group/{id}/users, where {id} placeholder will be replaced with a value you provided with groupId parameter during method call. So, this default parameter of GET annotation is just a path that should be appended to the server name and the value for placeholder is provided at the runtime.

Upvotes: 1

Adhikari Bishwash
Adhikari Bishwash

Reputation: 2780

/group/{id}/users this your GET request url (BASE_URL + Your GET url) where your id will be replaced with groupId passed in your groupList(@Path("id") int groupId); method.

Now your final request GET URL will be

BASE_URL + /group/{your groupId passed in method}/users

finally response from server will be parsed to List<User> and returned.

Upvotes: 0

Related Questions