Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is the difference between @Query and @path in Retrofit?

I wanted to use retrofit library for parsing and posting the data by passing some parameters. But When defining model class some times we will use @Serialized in-front of variable, What is the use of that Serialized.And What is the difference between @Get and @Query in passing params to API.Can Any one explain the difference.

like image 359
Shine Avatar asked Feb 09 '23 06:02

Shine


1 Answers

Lets say you have api method @GET("/api/item/{id}/subitem/") so by using @Path("id") you can specify id for item in path. However your api may take additional parameters in query like sort, lastupdatetime, limit etc so you add those at end of url by @Query(value = "sort") String sortQuery

So full method will look like:

@GET("/api/item/{id}/subitem")
SubItem getSubItem(@Path("id") int itemId, @Query("sort") String sortQuery, @Query("limit") int itemsLimit);

and calling api.getSubItem(5, "name", 10) will produce url @GET("/api/item/5/subitem/?sort=name&limit=10")

and @Get is HTTP method

http://www.w3schools.com/tags/ref_httpmethods.asp says

Two commonly used methods for a request-response between a client and server are: GET and POST.

GET - Requests data from a specified resource POST - Submits data to be processed to a specified resource

like image 187
Than Avatar answered Feb 11 '23 00:02

Than