Git Product home page Git Product logo

api-java-client-core's Introduction

Rest API SDK Core

Maven Central Build Status

Table of Contents

  1. Getting Started
  2. Exceptions
  3. Usage

Intro

Easily create Rest API clients by defining endpoint mappings and models that is going to be filled by JSON over HTTP

1. Getting Started

1.1 Create Rest Client

First you will need RestAPIClient.java object

RestAPIClient restClient = RestAPIClient.builder()
                                        .setBaseUrl("your_base_url")
                                        .build();

1.2 Create Model And Mapping

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;
}

1.3 Create Rest Client Endpoint

EntityModelEndpoint endpoint = restClient.createRetrofitEndpoint(EntityModelEndpoint.class);
// use endpoint...

2. Exceptions

  • 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

3. Usage

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

api-java-client-core's People

Contributors

connor-b-taboola avatar henryabra avatar nadavvitri avatar razkliger avatar vladimanaev avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.