zoukankan      html  css  js  c++  java
  • Retrofit最基本用法

    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);
    }
    
    
  • 相关阅读:
    hdu 1028 母函数 一个数有几种相加方式
    第m个全排列
    大数处理
    并查集
    KMP算法及KMP算法的应用(POJ2406)
    算法---分治法
    末学者笔记--NTP服务和DNS服务
    末学者笔记--NFS服务和DHCP服务讲解
    末学者笔记--SSHD服务及SCP用法
    末学者笔记——SAMBA服务、FTP服务讲解
  • 原文地址:https://www.cnblogs.com/FlySheep/p/5746153.html
Copyright © 2011-2022 走看看