springboot-mca-client
is a lightweight springboot http client framework. It aims to facilitate the management of APIs consumptions.
This project in on it's very early stage, all kinds of contibutions/feedback are welcome.
The API provider service should expose OpenAPI docs, for springboot applications please follow this link.
The API consumer service should include the following dependency:
<dependency>
<groupId>io.github.ahmedriahi</groupId>
<artifactId>springboot-mca-client</artifactId>
<version>0.0.4</version>
</dependency>
implementation 'io.github.ahmedriahi:springboot-mca-client:0.0.4'
Add both @EnableMcaClient
and @InterfaceComponentScan
to your main springboot application class
@EnableMcaClient
@InterfaceComponentScan
@SpringBootApplication
public class ConsumerApp {
public static void main(String[] args) {
SpringApplication.run(ConsumerApp.class, args);
}
}
Create Http client using @McaClient
and @HttpApiConsumer
annotations
@McaClient(providerName = "simple-api-provider")
public interface SimpleProviderAPIClient {
@HttpApiConsumer(method = PathItem.HttpMethod.GET, path = "/api/v1/string/lowercase/{value}")
String lowercase(@PathVariable("value") String value);
@HttpApiConsumer(method = PathItem.HttpMethod.POST, path = "/api/v1/calculation/{operation}")
CalculationResultPayload calculationUsingPathVariable(@PathVariable("operation") String operation, @RequestBody CalculationPayload value);
@HttpApiConsumer(method = PathItem.HttpMethod.POST, path = "/api/v1/calculation")
CalculationResultPayload calculationUsingRequestParam(@RequestParam("operation") String operation, @RequestBody CalculationPayload value);
}
Configure Http API provider using the following configuration, url attribute points to OpenAPI docs
mca:
providers:
simple-api-provider:
url: http://localhost:5050/v3/api-docs
Add OAuth configuration as follows, make sure that mca.providers.provider_name
is referenced using mca.spring.security.oauth2.client.registration.provider
mca:
providers:
simple-api-provider:
url: http://localhost:5050/v3/api-docs
secured-api-provider:
url: http://localhost:5051/v3/api-docs
spring:
security:
oauth2:
client:
registration:
secured-api-provider:
authorization-grant-type: client_credentials
client-id: --
client-secret: --
audience: --
provider: secured-api-provider
provider:
secured-api-provider:
token-uri: --
Samples are available here.