Update Post to use CreatedAtAction with Location header

Refactored the Post method to return a 201 Created response using CreatedAtAction. This change adds a Location header pointing to the Get action with the relevant actionId, and includes both the new record's ID and actionId in the response body. This improves API usability and aligns with RESTful conventions.
This commit is contained in:
2026-01-16 10:07:21 +01:00
parent c452724c9e
commit 2deb235c8d

View File

@@ -72,7 +72,7 @@ public class OutResController(IMediator mediator, IConfiguration config) : Contr
public async Task<IActionResult> Post([FromBody] InsertResultProcedure procedure, CancellationToken cancel)
{
var id = await mediator.ExecuteInsertProcedure(procedure, cancel: cancel);
return StatusCode(StatusCodes.Status201Created, id);
return CreatedAtAction(nameof(Get), new { actionId = procedure.ActionId }, new { id, procedure.ActionId });
}
/// <summary>