Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

retrofit android

def retrofit_version = "2.9.0"
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
Comment

retrofit implementation

dependencies {
    implementation "com.google.code.gson:gson:2.8.7"
    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-gson:2.9.0"

}
Comment

retrofit android

implementation 'com.squareup.retrofit2:retrofit:2.9.0'
Comment

retrofit

public interface MyApiEndpointInterface {
    // Request method and URL specified in the annotation
    // Callback for the parsed response is the last parameter

    @GET("users/{username}")
    void getUser(@Path("username") String username, Callback<User> cb);

    @GET("group/{id}/users")
    void groupList(@Path("id") int groupId, @Query("sort") String sort, Callback<List<User>> cb);

    @POST("users/new")
    void createUser(@Body User user, Callback<User> cb);
}
Comment

retrofit

dependencies {
    implementation 'com.google.code.gson:gson:2.8.7'
    implementation 'com.squareup.retrofit2:retrofit:2.9.0'
    implementation 'com.squareup.retrofit2:converter-gson:2.9.0'  

}
Comment

retrofit android

public interface GitHubService {
  @GET("users/{user}/repos")
  Call<List<Repo>> listRepos(@Path("user") String user);
}
Comment

retrofit

Gson gson = new GsonBuilder()
        .setDateFormat("yyyy-MM-dd'T'HH:mm:ssZ")
        .create();

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(BASE_URL)
    .addConverterFactory(GsonConverterFactory.create(gson))
    .build();
Comment

retrofit

RequestBody requestBody = new MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("title", "Square Logo")
        .addFormDataPart("image", "logo-square.png",
            RequestBody.create(MEDIA_TYPE_PNG, new File("website/static/logo-square.png")))
        .build();
Comment

retrofit

// Trailing slash is needed
public static final String BASE_URL = "http://api.myservice.com/";
Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(BASE_URL)
    .addConverterFactory(GsonConverterFactory.create())
    .build();
Comment

retrofit

User user = new User(123, "John Doe");
Call<User> call = apiService.createuser(user);
call.enqueue(new Callback<User>() {
  @Override
  public void onResponse(Call<User> call, Response<User> response) {

  }

  @Override
  public void onFailure(Call<User> call, Throwable t) {

  }
Comment

Retrofit interface

package com.vogella.java.retrofitgerrit;

import java.util.List;

import retrofit2.Call;
import retrofit2.http.GET;
import retrofit2.http.Query;

public interface GerritAPI {

    @GET("changes/")
    Call<List<Change>> loadChanges(@Query("q") String status);
}
Comment

Retrofit

// retrofit
implementation 'com.squareup.retrofit2:retrofit:2.1.0'
implementation 'com.squareup.retrofit2:converter-gson:2.1.0'

// Junit
testImplementation("org.junit.jupiter:junit-jupiter-api:5.0.0")
testRuntime("org.junit.jupiter:junit-jupiter-engine:5.0.0")
// to run JUnit 3/4 tests:
testImplementation("junit:junit:4.12")
testRuntime("org.junit.vintage:junit-vintage-engine:4.12.0")
Comment

retrofit

public interface MyApiEndpointInterface {
    // Request method and URL specified in the annotation

    @GET("users/{username}")
    Call<User> getUser(@Path("username") String username);

    @GET("group/{id}/users")
    Call<List<User>> groupList(@Path("id") int groupId, @Query("sort") String sort);

    @POST("users/new")
    Call<User> createUser(@Body User user);
}
Comment

retrofit

@Multipart
@POST("some/endpoint")
Call<Response> uploadImage(@Part("description") String description, @Part("image") RequestBody image)
Comment

PREVIOUS NEXT
Code Example
Java :: how to get the length of a jagged array java 
Java :: Java create an object of the static class Mammal 
Java :: two array structures in java 
Java :: Calling the Pre-Defined Method in Java 
Java :: firemonkey android ini file 
Java :: make pattern for V in jaca 
Java :: 2d matrix 
Java :: retrofit gradle 
Java :: change upper bar colour android studio 
Java :: java was started but returned exit code=13 
Java :: Java search() Method 
Java :: Lists - removing 
Java :: add words from string to collection java 
Java :: format code netbean 
Java :: efficient generic duplicate finding class java 
Java :: get alpha from image java 
Java :: for loop in firebase snapshot in java 
Java :: sudo visudo quit without saving 
Java :: OkHttp3 Never Timeout on slow internet 
Java :: get selected text in java 
Java :: create generator hibernate 
Java :: rules for naming variables in java 
Java :: take string , double and int value from useer using java 
Java :: Calling constructor methods in java 
Java :: how to find last digit in number by regex in java 
Java :: edit activity main drawer items text color android 
Java :: @javax.annotation.Generated error java stub 
Java :: plantuml java 
Java :: No Duplicate Key on HashMap 
Java :: domain validation test spring boot 
ADD CONTENT
Topic
Content
Source link
Name
9+8 =