正如問題中提到的,我需要構建一個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