Expand my Community achievements bar.

REST API Integration with Feign HTTP client | AEM Community Blog Seeding

Avatar

Administrator

BlogImage.jpg

REST API Integration with Feign HTTP client by Matija Kovaček

Abstract

1. Introduction
In projects we often have some integrations with API layer of 3rd party systems. This means that on our side we need to prepare HTTP client to be able consume those endpoints. Based on API specification we need to prepare Resource representation classes. Then, HTTP client with some configurations, like headers, timeouts, error handling. Parse request and response payloads into objects and many other things. All off this on the end creates a lot of boilerplate code.

Inspired with my latest project I want to introduce Feign HTTP client. Feign is HTTP client which goal is to simplify writing HTTP clients. Goal is to reduce complexity of REST API integrations.

With Feign we need to declare and annotate an interface based on API specification. And in background Feign will process annotations into a templated requests. Feign offers you to configure different HTTP clients, JSON/XML processors, metric providers, loggers and some other features.

2. Example
Throughout this article, we will integrate Faker APIs in Adobe Experience Manager (AEM) project. Goal is to get some fake generated data about users and addresses.

3. Setup
First, in your AEM project add needed dependencies.


io.github.openfeign
feign-core
11.0


io.github.openfeign
feign-jackson
11.0



com.fasterxml.jackson.core
jackson-core
2.12.0


com.fasterxml.jackson.core
jackson-annotations
2.12.0


com.fasterxml.jackson.core
jackson-databind
2.12.0

Besides the feign-core , additionaly we'll use feign-jackson for JSON processing. _ Feign-jackson _ requires jackson-core , jackson-annotations and _ jackson-databind _ dependencies.

To prevent unresolved import packages, we need to install those dependencies in Apache Felix Web console or embed them into our project bundle.

Embed dependencies in _ filevault-package-maven-plugin _ configuration.

Read Full Blog

REST API Integration with Feign HTTP client

Q&A

Please use this thread to ask the related questions.



Kautuk Sahni
1 Reply

Avatar

Level 1

I ran into this error with Open Feign in AEM 6.5. What am I missing?

 

org.osgi.framework.BundleException: Unable to resolve io.github.openfeign.feign-okhttp [585](R 585.0): missing requirement [io.github.openfeign.feign-okhttp [585](R 585.0)] osgi.wiring.package; (osgi.wiring.package=okhttp3) Unresolved requirements: [[io.github.openfeign.feign-okhttp [585](R 585.0)] osgi.wiring.package; (osgi.wiring.package=okhttp3)]
at org.apache.felix.framework.Felix.resolveBundleRevision(Felix.java:4368)
at org.apache.felix.framework.Felix.startBundle(Felix.java:2281)
at org.apache.felix.framework.Felix.setActiveStartLevel(Felix.java:1539)
at org.apache.felix.framework.FrameworkStartLevelImpl.run(FrameworkStartLevelImpl.java:308)
at java.base/java.lang.Thread.run(Thread.java:829)