Api package com.bw.zy1210.base.http; import com.bw.zy1210.base.entity.ShopTypeEntity; import com.bw.zy1210.base.entity.UserEntity; import com.bw.zy1210.base.entity.VideoEntity; import io.reactivex.Observable; import okhttp3.RequestBody; import retrofit2.http.Body; import retrofit2.http.GET; import retrofit2.http.POST; import retrofit2.http.Query; public interface Api { @GET("/video/findVideos") Observable<VideoEntity> video(@Query("currentPage") int currentPage,@Query("pageSize")int pageSize); @POST("/user/register") Observable<UserEntity> postRetister(@Body RequestBody body); @POST("/user/loginjson") Observable<UserEntity> postLoginjson(@Body RequestBody body); @POST("/goods/category") Observable<ShopTypeEntity> shoptype(); }
2.Retiofitutils
public class Retiofitutils { public Retiofitutils() { } private static Retiofitutils retiofitutils; private Retrofit retrofit; public static Retiofitutils getInstance() { if (retiofitutils == null) { retiofitutils=new Retiofitutils(); } return retiofitutils; } public Retrofit getRetrofit() { if (retrofit == null) { retrofit=creanteRetrofit(); } return retrofit; } public Retrofit creanteRetrofit(){ OkHttpClient okHttpClient=new OkHttpClient.Builder() .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BASIC)) .connectTimeout(180, TimeUnit.SECONDS) .readTimeout(180, TimeUnit.SECONDS) .writeTimeout(180, TimeUnit.SECONDS) .build(); Retrofit build = new Retrofit.Builder() .baseUrl("http://10.161.9.80:7012") .client(okHttpClient) .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build(); return build; } }