package qianxingzhe.retrofit_learning; import java.util.List; import java.util.Map; import retrofit2.Call; import retrofit2.http.Body; import retrofit2.http.Field; import retrofit2.http.FieldMap; import retrofit2.http.FormUrlEncoded; import retrofit2.http.GET; import retrofit2.http.POST; import retrofit2.http.Path; import retrofit2.http.Query; import retrofit2.http.QueryMap; /** * Created by lunyi.yly on 16/8/7. */ public interface GitHubService { @GET("repos/{owner}/{repo}/contributors") Call<List<Contributor>> listContributor(@Path("owner") String owner, @Path("repo") String repo); /** * 一個簡單的get請求。如: http://102.10.10.132/api/News * * @return */ @GET("News") Call<String> get_01(); /** * URL中有參數。如: http://102.10.10.132/api/News/1 * * @param newsId * @return */ @GET("News/{newsId}") Call<String> get_02(@Path("newsId") String newsId); /** * 參數在URL問號以後。如: http://102.10.10.132/api/News?newsId=1 * * @param newsId * @return */ @GET("News") Call<String> get_03(@Query("newsId") String newsId); /** * 多個參數在URL問號以後,且個數不肯定。如: http://102.10.10.132/api/News?newsId=1&type=類型1... * * @param map * @return */ @GET("News") Call<String> get_04(@QueryMap Map<String, String> map); /** * 須要補全URL,post的數據只有一條reason。如: http://102.10.10.132/api/Comments/1 * * @param newsId * @param reason * @return */ @FormUrlEncoded @POST("Comments/{newsId}") Call<String> post_01(@Path("newsId") String newsId, @Field("reason") String reason); /** * 須要補全URL,問號後加入access_token,post的數據只有一條reason。如:http://102.10.10.132/api/Comments/1?access_token=1234123 * * @param newsId * @param access_token * @param reason * @return */ @FormUrlEncoded @POST("Comments/{newsId}") Call<String> post_02(@Path("newsId") String newsId, @Query("access_tolen") String access_token, @Field("reason") String reason); /** * 須要補全URL,問號後加入access_token,post的數據有多條。如:http://102.10.10.132/api/Comments/1?access_token=1234123 * * @param newsId * @param access_token * @return */ @FormUrlEncoded @POST("Comments/{newsId}") Call<String> post_03(@Path("newsId") String newsId, @Query("access_tolen") String access_token, @FieldMap Map<String, String> map); /** * 須要補全URL,問號後加入access_token,post一個body(對象)。如:http://102.10.10.132/api/Comments/1?access_token=1234123 * * @param newsId * @param access_token * @param contributor * @return */ @FormUrlEncoded @POST("Comments/{newsId}") Call<String> post_04(@Path("newsId") String newsId, @Query("access_tolen") String access_token, @Body Contributor contributor); }