GithubHelp home page GithubHelp logo

horizon-4's Introduction

Horizon

Java HTTP client interfaces designed to make interacting with REST services as user-friendly as possible. Horizon classes use intuitive, fluent APIs and leverage Jackson internally so that reading and writing JSON are first-class citizens.

Features

  • Clean, simple interfaces
  • Designed to work with JSON
  • GZIP and Snappy support for compression/decompression
  • Built-in retry functionality with exponential backoff
  • Free to mix and match synchronous and asynchronous clients

Usage

The HorizonCore module contains all of the interfaces and domain objects. Horizon comes with two implementations, packaged in separate artifacts. The HorizonApache module contains an implementation of the synchronous HttpClient interface, built on top of Apache's httpclient 4. The HorizonNing module contains an implementation of both HttpClient and AsyncHttpClient built on top of org.asynchttpclient.shaded:async-http-client. So if you just want to use the Apache-based client, you would add the following Maven dependency:

<dependency>
  <groupId>com.hubspot</groupId>
  <artifactId>HorizonApache</artifactId>
  <version>0.2.0</version>
</dependency>

And then you can instantiate a new HttpClient by doing HttpClient httpClient = new ApacheHttpClient();

Examples

Using the synchronous HttpClient to retrieve a single Widget by ID:

public Widget getById(int id) {
    HttpRequest request = HttpRequest.newBuilder().setUrl("http://widgets/" + id).build();
    // Jackson is used to convert JSON response to Widget object
    return httpClient.execute(request).getAs(Widget.class);
}

Updating a widget:

public Widget update(Widget widget) {
    HttpRequest request = HttpRequest.newBuilder()
            .setMethod(Method.PUT)
            .setUrl("http://widgets/" + widget.getId())
            .setBody(widget) // Jackson is used to convert Widget to JSON
            .build();
    
    return httpClient.execute(request).getAs(Widget.class);
}

horizon-4's People

Contributors

chrisayoub avatar hs-jenkins-bot avatar hsjbao avatar jhaber avatar jw0x47 avatar mjball avatar ssalinas avatar stevie400 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.