This demo shows how a Swagger api definition can be used withing Bloomreach XM.
API definition
The Swagger API definition is defined in the demo.yaml file. It’s a simple api with two
end points, one that returns a list of users and one that returns the user details.
Server
A Spring boot application with a rest endpoint. The endpoint is generated with the API definition. Swagger
ui is available via http://localhost:8090/swagger-ui.html
Running the project:
$ mvn clean verify
$ mvn spring-boot:run
Bloomreach XM
Bloomreach XM consumes the API provided by the Spring boot server. For this a Spring client is generated based
on the api definition. The generation is done with the swagger-codegen-maven-plugin, see code below. This snippit
is from the site component pom.xml At line 13 the API spec is included.
link:brxm/site/components/pom.xml[role=include]
There are also some extra dependencies included (in this case among others: okhttp, gson) based on the choosen libray the dependencies differ.
The generated client is via Spring available in the HstComponents, Spring configuration in brxm-swagger/META-INF/hst-assembly/overrides/user-api-client.xml.
Spring configuration:
link:brxm/site/components/src/main/resources/META-INF/hst-assembly/overrides/user-api-client.xml[role=include]
Importent note: don’t forget to configure the connectTimeout (in milliseconds), default value depends on the used library.
In the hst component the Spring bean is available, see brxm/site/components/src/main/java/org/example/components/UserComponent.java
link:brxm/site/components/src/main/java/org/example/components/UserComponent.java[role=include]
Running the project:
$ mvn clean verify
$ mvn -P cargo.run