C
C#13mo ago
datasaur

What's the different use case for choosing between API with actions vs API with read/write endpoints

For example, action
[HttpGet]
public async Task<ActionResult<IEnumerable<Game>>> GetGame()
{
if (_context.Game == null)
{
return NotFound();
}
return await _context.Game.ToListAsync();
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Game>>> GetGame()
{
if (_context.Game == null)
{
return NotFound();
}
return await _context.Game.ToListAsync();
}
endpoint
routes.MapGet("/api/Game", async (GamesTestAPIContext db) =>
{
return await db.Game.ToListAsync();
})
.WithName("GetAllGames")
.Produces<List<Game>>(StatusCodes.Status200OK);
routes.MapGet("/api/Game", async (GamesTestAPIContext db) =>
{
return await db.Game.ToListAsync();
})
.WithName("GetAllGames")
.Produces<List<Game>>(StatusCodes.Status200OK);
2 Replies
Thinker
Thinker13mo ago
Pretty much depends on which you find more readable. Actions are older, while minimal APIs are the newer fancier way.
datasaur
datasaurOP13mo ago
thank you. i think i'll keep using controllers
Want results from more Discord servers?
Add your server