Git Product home page Git Product logo

bowtie-example's Introduction

Bowtie Example

This is simple example that uses Bowtie to create a client for Github API.

Getting started

Client

To start you need to provide an annotated interface that will map the API endpoints to an Java class.

RepositoryClient

public interface RepositoryClient {

  @Http(
      method = HttpMethod.GET,
      uri = "https://api.github.com/repos/{owner}/{repo}"
    )
  public Repository getRepository(
      @Path("owner") String owner,
      @Path("repo") String repo
    );
}

And create the Repository model that represents the JSON response.

Ribbon config

Also, provide a Ribbon config, like this.

# Max number of retries on the same server (excluding the first try)
github-client.ribbon.MaxAutoRetries=1

# Max number of next servers to retry (excluding the first server)
github-client.ribbon.MaxAutoRetriesNextServer=1

# Whether all operations can be retried for this client
github-client.ribbon.OkToRetryOnAllOperations=true

# Interval to refresh the server list from the source
github-client.ribbon.ServerListRefreshInterval=2000

# Connect timeout used by Apache HttpClient
github-client.ribbon.ConnectTimeout=3000

# Read timeout used by Apache HttpClient
github-client.ribbon.ReadTimeout=3000

# Initial list of servers, can be changed via Archaius dynamic property at runtime
github-client.ribbon.listOfServers=localhost:1080

github-client.ribbon.EnablePrimeConnections=true

hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=30000

Consumer

Finally, to consume the API:

ConfigurationManager.loadPropertiesFromResources("github-client.properties");

final RestAdapter restAdapter = RestAdapter.getNamedAdapter("github-client");
final RepositoryClient repoClient = restAdapter.create(RepositoryClient.class);

Repository repo = repoClient.getRepository("kenzanmedia", "bowtie");

That's all folks!

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.