Testing another articleTesting another articleTesting another articleTesting another articleTesting another articleTesting another articleTesting another articleTesting another article
using Microsoft.AspNetCore.Mvc;
namespace MyApp.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class SampleController : ControllerBase
{
// GET api/sample
[HttpGet]
public IActionResult Get()
{
return Ok("Hello, World!");
}
// GET api/sample/{id}
[HttpGet("{id}")]
public IActionResult Get(int id)
{
return Ok($"You requested ID: {id}");
}
// POST api/sample
[HttpPost]
public IActionResult Post([FromBody] SampleModel model)
{
if (ModelState.IsValid)
{
return CreatedAtAction(nameof(Get), new { id = model.Id }, model);
}
return BadRequest(ModelState);
}
}
public class SampleModel
{
public int Id { get; set; }
public string Name { get; set; }
}
}