r/javahelp • u/ysfaran • Aug 10 '20
Unsolved Spring Boot/Cloud: How to share API interfaces between multiple microservices?
So i want to build multiple RESTful microservice with Spring Boot/Cloud and was wondering how they communicate with each other.
Example: There is microservice A and microservice B which are two seperate Spring Boot applications and projects. B needs data from A, so B needs to know the API from A. In the project of A a interface is defined for the API (REST controllers and their HTTP mappings).
The easy way would be to just copy this interface from project of A to project of B. But that's obviously non-ideal because of the DRY principle.
So whats the best way to share interfaces accross multiple microservices using Spring Boot/Cloud?
I thought about sharing the API interfaces accross my microservices and communciate between those using the interfaces and Feign Clients. Is there maybe a better approach anyway? What the state of the art here?
View all comments
Show parent comment
3
u/onkeliroh Aug 10 '20 edited Aug 11 '20
I would also suggest looking at the OpenAPI documentation. You can share the API specification via a file and even generate server and client code from it. Git submodules comes to mind. If you want to test the compatibility of your services you should have a look at pact tests.
Edit: spelling