I'm in the school of thought of 'thin controllers', and love to push logic down into services and the domain models. However, I'm wondering if my controller should be making an HTTP Request to another web service or if the application service should do it. It seems that with my school of thinking then "yes" I should push it into the application service. However, this means the application service is stuck with HTTP only. So if I want to use a different communication protocol I'll need to implement another service like RabbitMQService instead of HttpService.
For example:
public Controller {
// POST api/controller
[HttpPost]
public async Task PostAsync([FromBody] Dictionary<string, int> data)
{
// get data from input json
var output = service.doWork();
// prep output data for outgoing HTTP Request
// this here or in a service like 'HttpService'?
await _sender.PostAsync(host + "/api/xxxxx", data);
}
}
Or have the application service send the PostAsync request?
ElectionServiceto retrieve aElectionby Id likeelectionService.GetElection(electionId). And then useElectionto vote for a candidate withelection.Vote(candidateId);. After the vote is recorded, I make another HTTP request to the candidates. This is not very RESTful and not the way I'd ever design/develop an application. But it's a demonstration in making API calls between web services.