Web API with ASPNet Core
I've been using WCF for all my Web services, but I was forced to replace a service with a Web API services.
Now I wont look back and I can now see why everyone pushing Web API over WCF.

Web API's are just so easy and flexible, especially using ASP.Net Core. If your use to using MVC, Web API should be a simple and no hassle service to create.
This Blog is simple example of how to create a simple get and post service within Web API

Create a MVC project
First thing you need to do it create an MVC project, if you don't have using a ASP.Net Core.

Add Web API controller
Right click on the Controller folder and select, click Add and select controller.
This then will show a dialog with options from MVC x Controller - Empty, MVC x Controller with read/write actions. You should be able to see a option saying Web API 2 Controller - Empty. Choose this option and give the new Web API controller a name.
This will create a new Web API Controller


public class DefaultController : ApiController
{
// GET: api/Default
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}

// GET: api/Default/5
public string Get(int id)
{
return "value";
}

// POST: api/Default
[HttpPost]
public PostReturnDataClass Post(PostSentDataClass sentObject)
{
PostReturnDataClass retunObject = new PostReturnDataClass();

...... Do some logic ..........
return retunObject;
}

// POST: api/Default/DOMORE
[HttpPost]
public PostReturnDataClass DOMORE(PostSentDataClass sentObject)
{
PostReturnDataClass retunObject = new PostReturnDataClass();

...... Do some logic and some more logic ..........
return retunObject;
}

}


Created: 07/04/2017 Total Comment: 0

Comments

(Not Displayed)
Human validation
Enter 9142 number, before submitting to confirm your human
[Home] [All Blogs] [Contact] [Me]