I want to update a record by calling my api endpoint using the put verb but his returns error 405 method not allowed.
My api endpoint:
app.MapPut("/sirs/{Id}", async (int Id, SIRCContext db, Sir sirc) =>
{
var record = await db.Sirs.FindAsync(Id);
if (record is null)
return Results.NotFound();
record.ActionTaken = sirc.ActionTaken;
record.Status = sirc.Status;
record.ResolvedDate = sirc.ResolvedDate;
record.FurtherActionRequired = sirc.FurtherActionRequired;
await db.SaveChangesAsync();
return Results.NoContent();
});
My client code:
public async Task UpdateSIRC(int id, Sir sirc)
{
try
{
await SetAuthToken();
var response = await _httpClient.PutAsJsonAsync($"/sirs/{id}", sirc);//Error here
response.EnsureSuccessStatusCode();
statusMessage = "Update Successful";
}
catch (Exception)
{
statusMessage = "Failed to update data.";
}
}
_httpClient?