Call Web API from C#

If you search in the web for calling web API from C# Code not from URL, you will find lots of sample on get and hardly enough on POST! I don't know why but I want to share with you a simple example. As a usual open visual studio and create a web API project from MVC project template.

Suppose these two simple post and get API actions:

  1.         [HttpPost]
  2.         [Route("api/Test/PostValue")]
  3.         public IHttpActionResult Po... Continue

IP filtering attribute for web API

Recently I came up with a solution for filtering the API requests by filtering the server IP. This is used when you want to make the received requests private and secure. It's a simple helper and I hope it could be useful for you as well.

  1. public class AuthorizeApiIPAddressAttribute : ActionFilterAttribute
  2.     {
  3.         public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
  4.         {
  5.     &nbs... Continue

Routing in Web API

If you have worked with MVC routing, you will find out that there are lots of similarities with web API and actually Web API uses the MVC standards on routing. There is only one difference and that's about using HTTP method in web API instead of URL path in MVC. In other word, Web API does not specify an action route parameter, bur it by default maps incoming requests to the appropriate action based upon the HTTP verb of the request.

Take a look at the following sample: 

  1. [HttpPut]
  2. public HttpResponseMessage Order... Continue