After a period of time on the study of flux some personal experience, specific reference flux
This presentation refreshes the interface based on the unidirectional flow of retrofit and okhttp and data streams. More Okhttp Use reference
Introduction based on flux data transfer:
1. Through the retrofit and Okhttp load network data through Gson parsing into Java objects, in flux mode to refresh the interface, transfer data.
2. Load data via action creator –>
3. Send data via Dispatcher (Action package data) –>
4.store–> send data via Dispatcher (Action package data) –>
5. To the interface layer (call the data update interface in store)
Specific process reference demo;
The following describes how network requests are in retrofit:
The //GET request can be used in the following way //Stitching request parameters behind weather @GET("Weather") call<weather> GetWeather (@Query("Location") String location,@Query("Output") String output,@Query("AK") String AK);//================================================================= //The following usage is from official website [http://square.github.io/retrofit/] (http://square.github.io/retrofit/) //Direct Request Interface @GET("Weather/list") call<weather> GetWeather ();//No annotation form, manual stitching parameters @GET("Weather/list?sort=desc") call<weather> getweathers ();//annotation form, replacing the value in {ID} to build the URL @GET("Weather/{id}/weathers") call<list<weather>> GetWeather (@Path("id")intWeatherid);///annotation form, replace the value in {ID} to build the URL, and stitch the request parameters @GET("Weather/{id}/weathers") call<list<weather>> GetWeather (@Path("id")intWeatherid,@Query("Sort") StringSort);///annotation form, replace the value in {ID} to build the URL, and stitch multiple request Parameters @GET("Weather/{id}/weathers") call<list<weather>> GetWeather (@Path("id")intWeatherid,@QueryMapmap<string, string> options);//====================================================== //Post request in the following manner //Below is the custom request body //Specifies that a custom request body needs to use a converter to transform the instance custom body. If you do not add a converter, you can only use Requestbodycan. @POST("Weather/new") call<weather> CreateUser (@BodyWeather user);//Forum form submission method, add request fields from the form with @field @FormUrlEncoded//encode the request URL @POST("Weather/edit") call<weather> Updateweather (@Field("First_Name") String First,@Field("Last_Name") String last);//Forum form submission method, add multiple request fields with @fieldmap similar to @querymap @FormUrlEncoded//encode the request URL @POST("Weather/edit") call<weather> Updateweather (@FieldMapmap<string, string> options);//====================================================== //PUT multipart, chunked request mode as follows //multi-part Request with @part Comment Declaration, and we can also inherit requestbody implementation of our custom Requestbody @Multipart @PUT("Weather/photo") call<weather> Updateweather (@Part("Photo") Requestbody photo,@Part("description") requestbody description);//Multi-part Request use @partmap Comment declaration. @Multipart @PUT("Weather/photo") call<weather> Updateweathers (@PartMapmap<string, requestbody> options);//====================================================== //define the request header using @headers annotations //The header of each request does not overwrite each other, even if a request with the same name is added to the requested request. //If the corresponding value in the request header is null, the header is ignored @Headers("cache-control:max-age=640000")//Custom Cache time @GET("Widget/list") call<list<weather>> widgetlist ();//Add multiple request headers @Headers({"Accept:application/vnd.github.v3.full+json","User-agent:retrofit-sample-app"})@GET("Users/{username}") call<weather> GetUser (@Path("username") String username);
Below provide the project source code
Above only personal thoughts if there is insufficient error, welcome message discussion advice.
Flux-retrofit-okhttp Package