Created
May 27, 2021 22:39
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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