retrofit 2 @path Vs @query

I am new to retrofit 2 library.I read several articles to get started as a beginner and I managed to fetch XML data from my RESTful API without specifying parameters.In my method that generated the XML resource is below.

public List<FoodPyramid> getFoodPyramid() {
    Session session = HibernateUtil.getSessionFactory().openSession();
    trans = session.beginTransaction();
    List<FoodPyramid> foodList = session.createQuery("from FoodPyramid").list();
    try {
    } catch (Exception e) {
        System.err.println("Food Pyramid fetch " + e);
    System.err.println("Am in the food modal. . . . . . . .");
    return foodList;

Now when I tried to pass parameter in the interface

Call<List<UserCredentail>> getUserOuth(@Query("username") String username, @Query("password") String password);  

It failed to run,no data was receive by a client . It took me a week trying to fix it though by using a non parameter call fetched the resources; So tried to change it to:

Call<List<UserCredentail>> getUserOuth(@Path("username") String username, @Path("password") String password);  

and it worked fine. So My question is: When do I need to use @Query and @Path Annotation in retrofit 2?

Answers 1

  • Consider this is the url:

    Now this is the call:

    Call<FilterResponse> getFilterList(
              @Path("Id") long customerId,
              @Query("Type") String responseType,
              @Query("SearchText") String searchText

    So we have:{Path}/filters?Type={Query}&SearchText={Query}

    Things that come after the ? are usually queries.

Sorry, you do not have a permission to answer to this question.