Reputation: 710
I am trying to use TemplateMethod pattern for creating ServiceBaseClass which will be called from RESTAPI
I am trying to create a wrapper API to call another API, another API will have around 50 endpoints
Need for using TemplateMethod is to provide abstract methods for creating requestURI and requestPaylod like below
public abstract class ServiceBase
{
// Template method
public Task<HttpResponseMessage> CallPostAPI()
{
var client = Utilities.GetHttpClient();
return client.PostAsync(CreateRequestURI(), CreateRequestBody());
}
// Abstract operations
public abstract string CreateRequestURI();
public abstract HTTPContent CreateRequestBody();
}
Problem is I will have to create 1 class for every request, rather I wish to create 1 class for every logical operation
What will be correct pattern to allow developers to create their own overridden implementation for creating request and responses and logic to call API will ne centralized or common
Upvotes: 0
Views: 112