Framework
How ApiHug design use the contract to eliminate the gap inner and external
Why contract is so import in internal or external communication?
Basically what ApiHug try to solve is API, which is a specification use to communication between different layers or systems.
In other words, it is a contract:
All those build base on ApiHug’s Api design meta language: protobuf
During the compile and runtime you can customize this behaviour easily with hope.common.service.contract.ContractAdapter
ApiHug uses the Service Locator pattern to load your custom ContractAdapter
at both runtime and compile time.
What you need to do:
ContractAdapter
stateless and provide a default constructor.hope.common.service.contract.ContractAdapter
under {APP-MODULE}/src/main/resources/META-INF
, and register your ContractAdapter
in it:#PKG-NAME#.infra.contract.MyContractAdapter
it will supply those extension for customized:
function | Remarks |
---|---|
moduleClassName | class name of this application’s proto module. |
contract | Control the api context from the given 3rd-party module(microservice api dependencies). |
mcp | Control the expose of MCP service base on API. |
How to use DSL to control your ApiContext in API contracts between different applications or MCP exposures:
instance of
//if module instanceof MyModule myModule:
return myModule.service()
.apiContext()
.orderService(
svc -> {
// Keep all the methods of this service
svc.keepAll();
// All the method start with, feel free try other shortcut
svc.startsWith("add");
// Pick method one by one
svc.methods(
methods -> {
// Include this method
methods.PlaceOrder();
// Exclude this method, start with `_`
methods._DeleteOrder();
});
})
.build();