Retrofit request class in Android learn with annu
Retrofit Request Class For Android
Android Hub
First of All Add these Dependency...................in Gradle build in Android
// retrofit dependencies
implementation 'com.squareup.retrofit2:retrofit:2.7.2'
implementation 'com.squareup.retrofit2:converter-gson:2.7.2'
implementation 'com.squareup.okhttp3:okhttp:3.6.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.1.0'
.............................................................................................................................
package com.daizzyinfo.food18.retrofit;
import static com.daizzyinfo.food18.utils.Constant.Token;
import java.io.IOException;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.scalars.ScalarsConverterFactory;
public class RetrofitRequest {
public static Retrofit retrofit = null;
public static Retrofit getRetrofit() {
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request newRequest = chain.request().newBuilder()
.addHeader("Authorization", "Bearer " + Token)
.build();
return chain.proceed(newRequest);
}
}).build();
if (retrofit == null) {
retrofit = new retrofit2.Retrofit.Builder()
.client(client)
.baseUrl("https://test-daizzyinfosys.com/food/api/")
.addConverterFactory(ScalarsConverterFactory.create())
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
package com.daizzyinfo.vidhikseva.retrofit;
import com.daizzyinfo.vidhikseva.jsonModel.CityJsonModel;
import com.daizzyinfo.vidhikseva.jsonModel.LawDetJsonModel;
import com.daizzyinfo.vidhikseva.viewModel.category.CatResponse;
import com.daizzyinfo.vidhikseva.viewModel.city.CityResponse;
import com.daizzyinfo.vidhikseva.viewModel.corporateLawyer.CorpLawResponse;
import com.daizzyinfo.vidhikseva.viewModel.coupon.CouponResponse;
import com.daizzyinfo.vidhikseva.viewModel.courts.CourtResponse;
import com.daizzyinfo.vidhikseva.viewModel.faqs.FaqResponse;
import com.daizzyinfo.vidhikseva.viewModel.lawyerDetails.LawyerDetResponse;
import com.daizzyinfo.vidhikseva.viewModel.lawyerList.LawyerListResponse;
import com.daizzyinfo.vidhikseva.viewModel.notification.NotifyResponse;
import com.daizzyinfo.vidhikseva.viewModel.state.StateResponse;
import com.daizzyinfo.vidhikseva.viewModel.banner.BannerResponse;
import com.daizzyinfo.vidhikseva.viewModel.search.SearchJsonModel;
import com.daizzyinfo.vidhikseva.viewModel.search.SearchResponse;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Headers;
import retrofit2.http.POST;
public interface ApiRequest {
@GET("customer/court")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<CourtResponse> getCourt(@Header("Token") String Token);
@POST("customer/faq-list")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<FaqResponse> getFaq(@Header("Token") String Token);
@GET("customer/all-coupons")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<CouponResponse> getCoupon(@Header("Token") String Token);
@GET("customer/category")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<CatResponse> getCategory(@Header("Token") String Token);
@GET("customer/state-list")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<StateResponse> getState(@Header("Token") String Token);
@POST("customer/city-list")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<CityResponse> getCitiesData(@Header("Token")String cookie , @Body CityJsonModel model);
@GET("customer/all-notifications")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<NotifyResponse> getAllNotifications(@Header("Token") String Token);
@GET("customer/corporate-lawyers")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<CorpLawResponse> getCorporateData(@Header("Token") String Token);
@POST("customer/lawyers-list")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<LawyerListResponse> getLawyerList(@Header("Token") String Token);
@POST("customer/lawyers-details")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<LawyerDetResponse> getLawDetails(@Header("Token") String cookie, @Body LawDetJsonModel model);
@POST("customer/search")
@Headers({"Accept: application/json","Content-Type: application/json"})
Call<SearchResponse> getSearchApi(@Header("Token") String cookie, @Body SearchJsonModel model);
@GET("customer/banner-list")
@Headers({"Accept: application/json, Content-Type: application/json"})
Call<BannerResponse> getBannerApi(@Header("Token") String cookie);
}


Comments
Post a Comment