Open JohanLarsson opened 5 years ago
namespace Meh { using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; [ApiController] public class OrdersController : Controller { private readonly Db db; public OrdersController(Db db) { this.db = db; } [HttpGet("api/orders/{id}")] public async Task<IActionResult> GetOrder([FromRoute]int id) { var match = await this.db.Orders.FirstOrDefaultAsync(x => x.Id == id); if (match == null) { return this.NotFound(); } return this.Ok(match); } [HttpGet("api/orders/{id}")] public async Task<IActionResult> GetOrderById([FromRoute]int id) { var match = await this.db.Orders.FirstOrDefaultAsync(x => x.Id == id); if (match == null) { return this.NotFound(); } return this.Ok(match); } } }
Need to ensure you only trigger on duplicate verbs at the same route - since it's fine to both GET and POST to the same endpoint to obtain a collection or create a new entity.
GET
POST