Refactor HTTP request handling in action loop
Updated the HTTP request handling logic within the action loop to dynamically construct requests based on the `RestType` and `EndpointUri` of each action. Expanded the switch statement to handle GET, POST, PUT, and DELETE methods, allowing for specific logic to be implemented for each. Removed the hardcoded URL and response content retrieval, indicating potential refactoring of response handling. The default case continues to throw a `BadRequestException` for unsupported REST types.
This commit is contained in:
parent
5b7fce8fd6
commit
eb402504ff
@ -24,27 +24,32 @@ public class InvokeRecActionCommandHandler(ISender sender) : IRequestHandler<Inv
|
||||
foreach (var action in actions)
|
||||
{
|
||||
using var http = new HttpClient();
|
||||
using var response = await http.GetAsync("https://example.com", cancel);
|
||||
|
||||
switch (action.RestType?.ToUpper().Trim())
|
||||
{
|
||||
case "GET":
|
||||
// Handle GET
|
||||
{
|
||||
using var response = await http.GetAsync(action.EndpointUri, cancel);
|
||||
break;
|
||||
}
|
||||
case "POST":
|
||||
{
|
||||
// Handle POST
|
||||
break;
|
||||
}
|
||||
case "PUT":
|
||||
{
|
||||
// Handle PUT
|
||||
break;
|
||||
}
|
||||
case "DELETE":
|
||||
{
|
||||
// Handle DELETE
|
||||
break;
|
||||
}
|
||||
default:
|
||||
throw new BadRequestException($"The REST type {action.RestType} is not supported.");
|
||||
}
|
||||
|
||||
var content = await response.Content.ReadAsStringAsync(cancel);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user