HTTP DELETE requests removal of a resource. In a board-game API, an endpoint can accept the game’s ID, find the record, delete it if present, save the change, and return a response DTO. Repeating the request for the same ID should have the same effect as making it once. section 5.5.2 section 1.1.4
A deletion endpoint can:
- Use the HttpDelete attribute and accept an integer ID. section 5.5.2
- Look up the record; if found, remove it through EF Core and save the changes. section 5.5.2
- Return a RestDTO containing the found record, or null if no record was found. section 5.5.2
- Treat deletion as a privileged operation: it can permanently change stored data, so authorization matters. section 5.5
Listing 5.11 BoardGameController’s Delete method
[HttpDelete(Name = "DeleteBoardGame")]
[ResponseCache(NoStore = true)]
public async Task<RestDTO<BoardGame?>> Delete(int id)
{
var boardgame = await _context.BoardGames
.Where(b => b.Id == id)
.FirstOrDefaultAsync();
if (boardgame != null)
{
_context.BoardGames.Remove(boardgame);
await _context.SaveChangesAsync();
};
return new RestDTO<BoardGame?>()
{
Data = boardgame,
Links = new List<LinkDTO>
{
new LinkDTO(
Url.Action(
null,
"BoardGames",
id,
Request.Scheme)!,
"self",
"DELETE"),
}
};
}
See the BoardGameController implementation, including its lookup, removal, save, and response-link logic. section 5.5.2
Verify deletion
In Swagger UI, execute DELETE /BoardGames with ID 181 to delete the Risk board game. The described test checks for an HTTP 200 response containing the targeted game’s information. section 5.5.2







