正如问题中提到的,我需要构建一个API接口进行改造。这是我的网址:如何构建API接口进行改造?
https://api.flightstats.com/flex/weather/rest/v1/json/all/COK?appId=XXXXXXXXX&appKey=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX&codeType=IATA
//--------------------------------------------------------^^^--------------------------------------------------------------------
如上标示,问题就出在位置COK
,这是一个机场代码,我需要它传递的要求,但我不能把它传给我在执行改造界面的创建。这是我的代码:
WeatherApiClient.class
public class WeatherApiClient {
public static final String BASE_URL = "https://api.flightstats.com/flex/weather/rest/v1/json/all/";
private static Retrofit retrofit = null;
public static Retrofit getClient() {
if (retrofit==null) {
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
WeatherApiInterface.class
public interface WeatherApiInterface {
@GET("COK") // this should be dynamic
Call<WeatherPojo> getValues(@Query("appId") String appId, @Query("appKey") String key, @Query("codeType") String code);
}
我应该如何改变我的代码,这样我也可以通过机场的代码,同时使一个要求?
我不太了解改造,但如何为getValues()添加“COK”?而且你需要位置的查询键。 (它应该是查询字符串中的someKey = COK。) – Toris
也许@Get(“。”)或者类似的。 – Toris