C
C#8mo 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);
3 Replies
datasaur
datasaur8mo ago
for context, I just started learning asp.net core coming from .net framework 4.6
Thinker
Thinker8mo ago
Pretty much depends on which you find more readable. Actions are older, while minimal APIs are the newer fancier way.
datasaur
datasaur8mo ago
thank you. i think i'll keep using controllers