Easily create Rest API clients by defining endpoint mappings and models that is going to be filled by JSON over HTTP
First you will need RestAPIClient.java object
RestAPIClient restClient = RestAPIClient.builder()
.setBaseUrl("your_base_url")
.build();
To know what is possible when creating endpoints interface please refer to Retrofit2 documentation
public class EntityModelExample {
private String id;
private String name;
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}
public interface EntityModelEndpoint {
@POST("/{account_id}")
@Headers("Content-Type: application/json")
EntityModelExample update(@Header("Authorization") String accessToken,
@Path("account_id") String accountId,
@Body EntityModelExample entity) throws RestAPIException;
}
EntityModelEndpoint endpoint = restClient.createRetrofitEndpoint(EntityModelEndpoint.class);
// use endpoint...
- RestAPIUnauthorizedException - Token is expired or bad credentials were supplied (HTTP status 401)
- Can be resolved by re-authentication or making sure that supplied credentials are correct
- RestAPIRequestException - Bad request (HTTP status 4xx)
- Can be resolved by fixing the request to a valid one
- RestAPIConnectivityException - Connectivity issues (HTTP status 5xx)
- Can be resolved by retrying or fixing networking issues
If your project is built with Maven add following to your pom file:
<dependency>
<groupId>com.taboola</groupId>
<artifactId>api-java-client-core</artifactId>
<version>x.y.z</version>
</dependency>
If your project is built with Gradle add following to your gradle setting file:
// https://mvnrepository.com/artifact/com.taboola/api-java-client-core
compile group: 'com.taboola', name: 'api-java-client-core', version: 'x.y.z'
Replace 'x.y.z' with the latest available version from Maven Central