将 Retrofit @GET 与 WeatherAPI 结合使用 - 静态参数

Using Retrofit @GET with a WeatherAPI - static parameters

我正在使用 OpenWeather API 并第一次尝试 Retrofit。我正在尝试提取 X 天的预测。可以在此处找到预测 API 的文档:

http://openweathermap.org/forecast16

看起来与特定城市的预测相关的 link 到 API 如下:

api.openweathermap.org/data/2.5/forecast/daily?q={city name},{country code}&cnt={cnt}

我的基础 URL 是:

api.openweathermap.org/data/2.5/forecast/daily?

我对如何满足我的@GET 批注和异步响应的关联方法感到有点困惑。 API link 中的“&”也令人困惑,因为我真的不知道我会在我的@GET 注释中包含 API 调用的静态部分。这是我拥有的:

public interface WeatherAPI {

@GET("/forecast/daily?")
void getResponse(@Query("city")String city, @Query("country_code") int countryCode, @Query("number_of_days") int number_of_days, Callback<List<WeatherForecast>> response);

 }

任何有关此特定问题的帮助以及如何解决一般的 Retrofit 将不胜感激。

它应该可以正常工作。 Retrofit 处理 & 符号。

public interface WeatherAPI {
    @GET("/forecast/daily?")
    void getResponse(
                    @Query("city") String city,
                    @Query("country_code") int countryCode,
                    @Query("number_of_days") int number_of_days,
                    Callback<List<WeatherForecast>> response
    );    
}

我有一个这样的 API 端点:

http://myserver.com/api/posts/?page_size=5&page=1

这是我的 Retrofit 界面方法:

@GET("/posts/")
void getPostPage(
                 @Query("page") int page,
                 @Query("page_size") int pageSize,
                 Callback<PostPage> callback
);