[HttpGet] public IActionResult Get() { // Get data from database var data = GetDataFromDatabase(); return Ok(data); }
[HttpPost] public IActionResult Post([FromBody] MyModel model) { // Process model data var result = ProcessModelData(model); if (result == true) { return Ok(); } else { return BadRequest(); } }In this example, the Ok method is used to return a success status code (200) in response to a successful POST request that processes model data. If the result of the processing operation is not successful, then a BadRequest status code (400) is returned instead. ResponseResult Ok is part of the Microsoft.AspNetCore.Mvc.Core package library.