Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created May 27, 2021 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manoj-choudhari-git/26eb50c68765057c000ff1f2949402f4 to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/26eb50c68765057c000ff1f2949402f4 to your computer and use it in GitHub Desktop.
ASP .NET Core Web API controller showing Route attribute and HTTP verb attributes
[Route("api/[controller]")]
[ApiController]
public class ValuesController1 : ControllerBase
{
// GET: api/Values
[HttpGet]
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/Values/5
[HttpGet("{id}")]
public string Get(int id)
{
return "value";
}
// POST api/Values
[HttpPost]
public void Post([FromBody] string value)
{
}
// PUT api/Values/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/Values/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment