I am trying to make a HttpDelete request have multiple parameters. I cannot use the body and I don't want to use HttpPost.
This is my action:
[HttpDelete("{ids}")]
public async Task Delete(int[] ids)
{
foreach(int id in ids)
await _repository.DeleteLogAsync(id);
}
And this is the code I use for sending the request:
public async Task DeleteLogs(int[] ids)
{
var queryString = HttpUtility.ParseQueryString(string.Empty);
foreach (var id in ids)
{
queryString.Add("id", id.ToString());
}
var url = _configuration["BaseUrl"] + _configuration["Endpoint"] + "/" + queryString.ToString();
using (var httpClient = new HttpClient())
{
var response = await httpClient.DeleteAsync(url);
response.EnsureSuccessStatusCode();
}
}
I also use Swagger and it shows me the following:
If I try sending the request exactly as it's shown above, I get a 415 response. I also find it weird that swagger expects two parameters, one in body and one in the query.
So I tried using [FromQuery]
in my action. In this case, the request goes through but the int array is empty in my action. So I am kinda stuck and don't know how to proceed. As per this answer, it should work.
Can anyone tell me what I am doing wrong?