Below are the steps to implement WebAPI:
Step 1: Create the project using the WebAPI template.
Step 2: Once you have created the project you will notice that the controller now inherits from ApiController
and you can now implement POST, GET, PUT, and DELETE methods of the HTTP protocol.
public class ValuesController : ApiController
{
// GET api/values
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET api/values/5
public string Get(int id)
{
return "value";
}
// POST api/values
public void Post([FromBody]string value)
{
}
// PUT api/values/5
public void Put(int id, [FromBody]string value)
{
}
// DELETE api/values/5
public void Delete(int id)
{
}
}
Step 3: If you make an HTTP GET call you should get the below results: