Lundegaard Commons :: Rest Commons Library

Library used for quick creation of REST clients

Лицензия

Лицензия

Категории

Категории

Java Языки программирования
Группа

Группа

eu.lundegaard.commons.java
Идентификатор

Идентификатор

rest
Последняя версия

Последняя версия

0.2.0
Дата

Дата

Тип

Тип

jar
Описание

Описание

Lundegaard Commons :: Rest Commons Library
Library used for quick creation of REST clients
Ссылка на сайт

Ссылка на сайт

https://github.com/lundegaard/lundegaard-commons-java-rest
Организация-разработчик

Организация-разработчик

Lundegaard a.s.
Система контроля версий

Система контроля версий

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

Скачать rest

Как подключить последнюю версию

<!-- 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"]

Зависимости

compile (8)

Идентификатор библиотеки Тип Версия
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)

Идентификатор библиотеки Тип Версия
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

Модули Проекта

Данный проект не имеет модулей.

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.

Версии библиотеки

Версия
0.2.0
0.1.0