Lundegaard Commons :: Rest Commons Library

Library used for quick creation of REST clients

License

License

Categories

Categories

Java Languages
GroupId

GroupId

eu.lundegaard.commons.java
ArtifactId

ArtifactId

rest
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

Lundegaard Commons :: Rest Commons Library
Library used for quick creation of REST clients
Project URL

Project URL

https://github.com/lundegaard/lundegaard-commons-java-rest
Project Organization

Project Organization

Lundegaard a.s.
Source Code Management

Source Code Management

https://github.com/lundegaard/lundegaard-commons-java-rest/tree/master

Download rest

How to add to project

<!-- https://jarcasting.com/artifacts/eu.lundegaard.commons.java/rest/ -->
<dependency>
    <groupId>eu.lundegaard.commons.java</groupId>
    <artifactId>rest</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/eu.lundegaard.commons.java/rest/
implementation 'eu.lundegaard.commons.java:rest:0.2.0'
// https://jarcasting.com/artifacts/eu.lundegaard.commons.java/rest/
implementation ("eu.lundegaard.commons.java:rest:0.2.0")
'eu.lundegaard.commons.java:rest:jar:0.2.0'
<dependency org="eu.lundegaard.commons.java" name="rest" rev="0.2.0">
  <artifact name="rest" type="jar" />
</dependency>
@Grapes(
@Grab(group='eu.lundegaard.commons.java', module='rest', version='0.2.0')
)
libraryDependencies += "eu.lundegaard.commons.java" % "rest" % "0.2.0"
[eu.lundegaard.commons.java/rest "0.2.0"]

Dependencies

compile (8)

Group / Artifact Type Version
eu.lundegaard.commons.java : jackson jar 3.2.0
eu.lundegaard.commons.java : utils jar 3.2.0
com.fasterxml.jackson.core : jackson-databind jar 2.10.2
io.github.openfeign : feign-core jar 10.7.4
io.github.openfeign : feign-jackson jar 10.7.4
io.github.openfeign : feign-slf4j jar 10.7.4
commons-io : commons-io jar 2.6
org.slf4j : slf4j-api jar 1.7.30

test (5)

Group / Artifact Type Version
com.github.tomakehurst : wiremock jar 2.26.0
junit : junit jar 4.13
org.assertj : assertj-core jar 3.15.0
org.json : json jar 20190722
org.apache.httpcomponents : httpcore jar 4.4.13

Project Modules

There are no modules declared in this project.

Lundegaard Java Commons - Rest Client

This library is used for simple creation of REST clients using the OpenFeign library.

Usage

Just add it as dependency, e.g. into Maven (use the latest version)

<dependency>
    <groupId>eu.lundegaard.commons.java</groupId>
    <artifactId>rest</artifactId>
    <version>${lundegaard.commons.rest.version}</version>
</dependency>

Prepare client interface

Define your Feign client interface as you are accustomed to. See OpenFeign documentation.

public interface GoogleMapsClient {
    @RequestLine("GET /maps/api/geocode/json?address={add}&sensor=false")
    @Headers("Accept: application/json")
    GoogleResponse convertToLatLong(@Param("add") String address);
}

Instantiate and use client

Instantiate your Feign client interface implementation using Lundegaard Java Commons Rest and call remote API. Client is preconfigured to throw FeignClientException is case when error is received from the server call (eg. not 2xx success status code).

public class YourClass {
public Coordinates getLundegaardCoordinates() {
    GoogleMapsClient googleClient = FeignClientUtil.client(GoogleMapsClient.class, "http://maps.googleapis.com");
    GoogleResponse googleResponse = googleClient.convertToLatLong("Sokolovská 651/136a Prague");
    
    return googleResponse.getCoordinates();
}
}

Configure client

Lundegaard Commons Java Rest provides preconfigured client implementation. It includes

  • JSON (de)serialization
  • Byte array deserialization
  • Logging
  • Error handling

You may change or extend default configuration using Feign builder

public GoogleMapsClient createGoogleMapsClient() {
    return FeignClientUtil.builder(GoogleMapsClient.class)
        // Do your configuration. For example retry when service is unavailable
        // .retryer(new MyRetryer())
        .target(GoogleMapsClient.class, "http://maps.googleapis.com");
}
eu.lundegaard.commons.java

Lundegaard a.s.

Versions

Version
0.2.0
0.1.0