retrofit2

retrofit 2 @path Vs @query

穿精又带淫゛_ 提交于 2019-12-03 01:09:49
问题 I am new to retrofit 2 library.I read several articles to get started as a beginner and I managed to fetch XML data from my RESTful API without specifying parameters.In my method that generated the XML resource is below. @GET @Path("/foods") @Produces(MediaType.APPLICATION_XML) public List<FoodPyramid> getFoodPyramid() { Session session = HibernateUtil.getSessionFactory().openSession(); trans = session.beginTransaction(); List<FoodPyramid> foodList = session.createQuery("from FoodPyramid")

Retrofit 2 HTTP method annotation is required (e.g., @GET, @POST, etc.)

*爱你&永不变心* 提交于 2019-12-02 23:24:05
What's wrong with my Retrofit configuration? I'm having this error when I'm adding Basic Authentication with my OkHttpClient but when I used the default client without Interceptor it's working. Or is there something wrong with my Gradle Dependencies..? E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalArgumentException : HTTP method annotation is required (e.g., @GET, @POST, etc.). for method APIService.getRegAccrDetails at retrofit.Utils.methodError(Utils.java:177) at retrofit.Utils.methodError(Utils.java:167) at retrofit.RequestFactoryParser.parseMethodAnnotations(RequestFactoryParser

Android Retrofit 2 + RxJava: listen to endless stream

廉价感情. 提交于 2019-12-02 23:20:10
Can I use Retrofit + RxJava to listen to an endless stream? For instance the Twitter stream. What I have is this: public interface MeetupAPI { @GET("http://stream.meetup.com/2/rsvps/") Observable<RSVP> getRSVPs(); } MeetupAPI api = new Retrofit.Builder() .baseUrl(MeetupAPI.RSVP_API) .addCallAdapterFactory(RxJavaCallAdapterFactory.create()) .addConverterFactory(GsonConverterFactory.create()) .build() .create(MeetupAPI.class); api.getRSVPs() .subscribeOn(Schedulers.newThread()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(rsvp -> Log.d(TAG, "got rsvp"), error -> Log.d(TAG, "error: " +

Unable to create call adapter for io.reactivex.Observable

夙愿已清 提交于 2019-12-02 19:52:59
I'm going to send a simple get method to my server(it is Rails app) and get the result using RxJava and Retrofit. The thing that I did is: My interface: public interface ApiCall { String SERVICE_ENDPOINT = "https://198.50.214.15"; @GET("/api/post") io.reactivex.Observable<Post> getPost(); } My model is this: public class Post { @SerializedName("id") private String id; @SerializedName("body") private String body; @SerializedName("title") private String title; public String getId () { return id; } public String getBody () { return body; } public String getTitle () { return title; } } And this is

Error when using Retrofit

一曲冷凌霜 提交于 2019-12-02 19:31:13
问题 I'm trying to get data from web server.I'n new with Retrofit ,and I have error "No Retrofit annotation found (parameter#1)" when try launch my app,I dont understand what cause this error and what to do with that. VideoApi class: public interface VideoApi { @GET("/videos/featured") Call<Video> getFeaturedVideo(Callback<List<Video>> response); } Video class: public class Video { private String url,title,description; private int score; public String getUrl() { return url; } public void setUrl

Retrofit 2 - Elegant way of adding headers in the api level

梦想与她 提交于 2019-12-02 18:45:39
My Retrofit 2 ( 2.0.2 currently) client needs to add custom headers to requests. I'm using an Interceptor to add these headers to all requests: OkHttpClient httpClient = new OkHttpClient(); httpClient.networkInterceptors().add(new Interceptor() { @Override public Response intercept(Chain chain) throws IOException { final Request request = chain.request().newBuilder() .addHeader("CUSTOM_HEADER_NAME_1", "CUSTOM_HEADER_VALUE_1") .addHeader("CUSTOM_HEADER_NAME_2", "CUSTOM_HEADER_VALUE_2") ... .addHeader("CUSTOM_HEADER_NAME_N", "CUSTOM_HEADER_VALUE_N") .build(); return chain.proceed(request); } });

How to download PDF file with Retrofit and Kotlin coroutines?

痞子三分冷 提交于 2019-12-02 17:02:07
问题 I saw topics like How to download file in Android using Retrofit library?, they use @Streaming and RxJava / callbacks. I have Kotlin, coroutines, Retrofit 2.6.0 and queries like in https://stackoverflow.com/a/56473934/2914140: @FormUrlEncoded @Streaming @POST("export-pdf/") suspend fun exportPdf( @Field("token") token: String ): ExportResponse I have a Retrofit client: retrofit = Retrofit.Builder() .baseUrl(SERVER_URL) .client(okHttpClient) .build() service = retrofit.create(Api::class.java)

Retrofit2 Authorisation with Bearer Token

孤人 提交于 2019-12-02 16:59:00
I'm trying to use Retrofit2 , I want to add Token to my Header Like this: Authorization: Bearer Token but the code below doesn't work: public interface APIService { @Headers({"Authorization", "Bearer "+ token}) @GET("api/Profiles/GetProfile?id={id}") Call<UserProfile> getUser(@Path("id") String id); } My server is asp.net webApi . Please help what should I do? You have two choices -- you can add it as a parameter to your call -- @GET("api/Profiles/GetProfile?id={id}") Call<UserProfile> getUser(@Path("id") String id, @Header("Authorization") String authHeader); This can be a bit annoying

retrofit 2 @path Vs @query

橙三吉。 提交于 2019-12-02 16:35:35
I am new to retrofit 2 library.I read several articles to get started as a beginner and I managed to fetch XML data from my RESTful API without specifying parameters.In my method that generated the XML resource is below. @GET @Path("/foods") @Produces(MediaType.APPLICATION_XML) public List<FoodPyramid> getFoodPyramid() { Session session = HibernateUtil.getSessionFactory().openSession(); trans = session.beginTransaction(); List<FoodPyramid> foodList = session.createQuery("from FoodPyramid").list(); try { trans.commit(); session.close(); } catch (Exception e) { session.close(); System.err

Android Unit Test with Retrofit2 and Mockito or Robolectric

故事扮演 提交于 2019-12-02 14:09:49
Can I test real response from retrofit2beta4? Do i need Mockito or Robolectic? I don't have activities in my project, it will be a library and I need to test is server responding correctly. Now I have such code and stuck... @Mock ApiManager apiManager; @Captor private ArgumentCaptor<ApiCallback<Void>> cb; @Before public void setUp() throws Exception { apiManager = ApiManager.getInstance(); MockitoAnnotations.initMocks(this); } @Test public void test_login() { Mockito.verify(apiManager) .loginUser(Mockito.eq(login), Mockito.eq(pass), cb.capture()); // cb.getValue(); // assertEquals(cb.getValue(