Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save nishapanFFF/8616860f5763f9ac3903f9dd6a2d27dd to your computer and use it in GitHub Desktop.
Save nishapanFFF/8616860f5763f9ac3903f9dd6a2d27dd to your computer and use it in GitHub Desktop.
public class FooClient {
private static final String CLIENT_ID = BackendClients.FOO.id;
static final String DOWORK_PATH = "/do-work"; // existing header versioning
static final String DOWORK_V2_PATH = "/v2/do-work"; // new version of existing endpoint path versioning
static final String DOOTHERWORK_V1_PATH = "/v1/do-other-work"; // new endpoint path versioning
private final DynamicHoneycombClient client;
// TO BE DEPRECATED
private final FooApiVersion apiVersion;
private final String host;
// TO BE DEPRECATED: existing constructor with header versioning
public FooClient(String host,
DynamicHoneycombClient honeycombClient,
FooApiVersion apiVersion) {
this.host = host;
this.client = honeycombClient;
this.apiVersion = apiVersion;
}
// new constructor, version agnostic
public FooClient(String host,
DynamicHoneycombClient honeycombClient) {
this.host = host;
this.client = honeycombClient;
this.apiVersion = apiVersion;
}
// TO BE DEPRECATED: existing endpoint with header versioning
public void doWork(Object request) {
String response =
sendRequest(DOWORK_PATH, HttpVerb.POST, apiVersion.getValue(), request);
}
// new version of existing endpoint with path versioning
public void doWorkV2(Object request) {
String response =
sendRequest(DOWORK_V2_PATH, HttpVerb.POST, request);
}
// new endpoint (v1) with path versioning
public void doOtherWorkV1(Object request) {
String response =
sendRequest(DOOTHERWORK_V1_PATH, HttpVerb.POST, request);
}
}
/* BarService consuming FooClient */
// TO BE DEPRECATED: existing client autowire
@Bean
public FooClient fooClient() {
return new FooClient(fooHost, dynamicHoneycombClient, FooApiVersion.V1);
}
// new client autowire for path versioning
@Bean
public FooClient fooClientWithPathVersioning() {
return new FooClient(fooHost, dynamicHoneycombClient);
}
// TO BE DEPRECATED: existing call to doWork v1
fooClient.doWork(request);
// new call to doWork v2
fooClientWithPathVersioning.doWorkV2(request);
// new call to doOtherWork v1
fooClientWithPathVersioning.doOtherWorkV1(request);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment