Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Java REST client with Feign

igor
November 02, 2016

Java REST client with Feign

Talk at DevFest Toulouse (03 Nov 2016)

igor

November 02, 2016
Tweet

More Decks by igor

Other Decks in Programming

Transcript

  1. ď whoami Igor Laborie Expert Java & Web,  @ilaborie

     [email protected] #DevFestToulouse #Feign @ilaborie 2 Connected to BrowserSync
  2. Roadmap 1. Basic Đ CRUD operations, JSON 2. Advanced Đ

    Async with RxJava Đ Circuit Breaker with Hystrix Đ HTTP/2 with Java 9 #DevFestToulouse #Feign @ilaborie 3 Connected to BrowserSync
  3. ď whois feign Ÿ https://github.com/OpenFeign/feign Open Source: license Apache 2.0

    A Netflix Project Java 7+, Java 8 friendly Not opinionated #DevFestToulouse #Feign @ilaborie 5 Connected to BrowserSync
  4. ď du -h target/*.jar Classes Fat jar Jersey (JAX-RS 2)

    112 4,6 Mo Retrofit 2 38 740 Ko Feign 34 336 Ko *: only into javax.ws.rs Ÿ See code on github #DevFestToulouse #Feign @ilaborie * 6 Connected to BrowserSync
  5. Most Java applications require a persistent class representing felines. Hibernate

    Documentation ... #DevFestToulouse #Feign @ilaborie “ 7 Connected to BrowserSync
  6. Most Java applications require a microservice for felines. Any buzzword

    addicts #DevFestToulouse #Feign @ilaborie “ 8 Connected to BrowserSync
  7. ď curl http://cats/swagger Run with: docker run -p 8080:8080 ilaborie/cats-microservice

    Ÿ See code on github #DevFestToulouse #Feign @ilaborie 9 Connected to BrowserSync
  8. Đ Live coding CRUD operations, JSON Ÿ See code on

    github #DevFestToulouse #Feign @ilaborie 10 Connected to BrowserSync
  9. Encoders & Decoders • JSON with GSON: feign-gson or Jackson:

    feign-jackson • XML with JAXB: feign-jaxb , Jackson JAXB: jackson-jaxb or SAX: feign-sax (decoder only) #DevFestToulouse #Feign @ilaborie 11 Connected to BrowserSync
  10. Under the hood Ä No White/Dark Magic The java.lang.re ect.Proxy

    allow you to dynamically implement the interface. Use the java.net.HttpURLConnection to send and process HTTP requests. (by default) Use the reflection API to extract meta-data. If you prefer JAX-RS annotation you can use feign-jaxrs . #DevFestToulouse #Feign @ilaborie 12 Connected to BrowserSync
  11. How to be async ? Do not write a custom

    feign.Decoder ! You can use Java 8 CompletableFuture Or the feign-hystrix provide RxJava support #DevFestToulouse #Feign @ilaborie 14 Connected to BrowserSync
  12. Đ Live coding Async with Ÿ See code on github

    #DevFestToulouse #Feign @ilaborie 15 Connected to BrowserSync
  13. Circuit Breaker By Bidgee (Own work) CC BY-SA 3.0, via

    Wikimedia Commons #DevFestToulouse #Feign @ilaborie 16 Connected to BrowserSync
  14. Đ Live coding Circuit Breaker with Ÿ See code on

    github #DevFestToulouse #Feign @ilaborie 17 Connected to BrowserSync
  15. Incoming train .... % Download Java 9 Early Access Can

    be downloaded with/without Jigsaw Or use docker: docker run openjdk:9 java -version docker run maven:3-jdk-9 mvn -version #DevFestToulouse #Feign @ilaborie 18 Connected to BrowserSync
  16. JEP 110: HTTP/2 Client 7 java.net.http URI uri = new

    URI("http://127.0.0.1:8080/hello") HttpResponse resp = HttpRequest.create(uri) .GET().response(); int statusCode = resp.statusCode(); String body = resp.body(HttpResponse.asString()); System.out.printf("[%s] %s\n", statusCode, body); #DevFestToulouse #Feign @ilaborie 01. 02. 03. 04. 05. 06. 19 Connected to BrowserSync
  17. Đ Live coding Custom feign.Client with Ÿ See code on

    github #DevFestToulouse #Feign @ilaborie 20 Connected to BrowserSync
  18. feign.Client implementation • Apache HttpClient: feign-httpclient • OkHttp: feign-okhttp HTTP/2

    & caching support • Ribbon: feign-ribbon Load balancing support #DevFestToulouse #Feign @ilaborie 21 Connected to BrowserSync
  19. So why feign: Open & active community Simple & intuitive

    Extensible, useful plugins, easy to write your own Not opinionated #DevFestToulouse #Feign @ilaborie 22 Connected to BrowserSync