Skip to main content

Posts

Showing posts with the label Web API

Versioning ASP.NET Web API Services uri based Versioning

I’ve been doing some work with APIs lately and finally had the chance to dig into the  ASP.NET Web API  a bit more. While it’s technically brand new (released with .NET 4.5 and Visual Studio 2012), the Web API has been around in beta form for quite a bit now. For those of us who have done a fair amount of work with the WCF framework, the Web API is a welcome addition/replacement. Instead of monstrous configuration files and contract-first demands placed on us by WCF, we can now build RESTful web services using a very lightweight and HTTP-focused framework. As I work on designing a new API, one thing that I’m focused on right now is versioning.   In this blog post, I’ll show you how to build uri based versioning for ASP.NET Web API services. Reference  https://seroter.wordpress.com/2012/09/25/versioning-asp-net-web-api-services-using-http-headers/ http://www.codeproject.com/Articles/741326/Introduction-to-Web-API-Versioning http://bitoftech.net/2013/12/16/as...

WEB API: PASSING A COMPLEX TYPE IN JSON USING J QUERY

In my  project i wanted to pass a complex type to the Post method of an Web Api controller. The Post itself will be done using JQuery in the JSON format. I noticed that the parameter was always null. After a bit of searching i found the solution Server Side code   public class ValuesController : ApiController     {         public class MyComplexType         {             public string Name { get; set; }             public MyComplexSubType MyComplexSubType { get; set; }         }         public class MyComplexSubType         {             public int Age { get; set; }         }         // GET api/<controller>         public IEnumerable<string> Get()      ...

How to alias json response model properties in ASP.Net Web API

If you want to return objects from action methods in Web Api with JSON style lowercase names, is there a way to alias the property names so that the C# object below looks like the JSON object that follows. Sample C# Response Model     public class Account     {         public int Id { get; set; }         public string AccountName { get; set; }         public decimal AccountBalance { get; set; }     } JSON that I'd like to be returned     {         "id" : 12,         "account-name" : "Primary Checking",         "account-balance" : 1000     } Answer  :  Yes   You can use JSON.NET's JsonProperty  public class Account     {         [JsonProperty(PropertyName="id")]         public int Id { get; set; }       ...

ASP.NET Web Api Validation with Data Annotations

I’ve recently moved a project over Web Api over to ASP.NET Web Api. In doing that I needed to re-implement my validation code. Thanks to the Api being a part of the MVC framework, things are much simpler now.   Previously I was Explained About   Difference between WCF and Web API and WCF REST and Web Service  ,   Repeater Vs. DataList vs. ListView Vs. GridView  ,  IEnumerable VS IQueryable public class ValidationActionFilter : ActionFilterAttribute {      public override void OnActionExecuting(HttpActionContext context)      {          var modelState = context.ModelState;          if (!modelState.IsValid)          {              dynamic errors = new JsonObject();      ...

IEnumerable VS IQueryable

Difference Between IEnumerable and IQueryable in ap.net ? In LINQ to query data from database and collections, we use IEnumerable and IQueryable for data manipulation. IEnumerable is inherited by Iqueryable, hence it has all the features of it and except this, it has its own features. Both have its own importance to query data and data manipulation. Let’s see both the features and take the advantage of both the features to boost your LINQ Query performance. Previously I was Explained About   Difference between WCF and Web API and WCF REST and Web Service  ,   Repeater Vs. DataList vs. ListView Vs. GridView IEnumerable IEnumerable exists in System.Collections Namespace. IEnumerable can move forward only over a collection, it can’t move backward and between the items. IEnumerable is best to query data from in-memory collections like List, Array etc. While query data from database, IEnumerable execute select query on server si...

Difference between ASP.NET MVC and ASP.NET Web API

While developing your web application using MVC, many developers got confused when to use Web API, since MVC framework can also return JSON data by using JsonResult and can also handle simple AJAX requests. In previous article, I have explained the Difference between WCF and Web API and WCF REST and Web Service and when to use Web API over others services. In this article, you will learn when to use Web API with MVC. Asp.Net Web API VS Asp.Net MVC Asp.Net MVC is used to create web applications that returns both views and data but Asp.Net Web API is used to create full blown HTTP services with easy and simple way that returns only data not view. Web API helps to build REST-ful services over the .NET Framework and it also support content-negotiation(it's about deciding the best response format data that could be acceptable by the client. it could be JSON,XML,ATOM or other formatted data), self hosting which are not in MVC. Web API also takes care of returning d...

What is Web API and why to use it ?

What is Web API and why to use it ? Asp.Net Web API is a framework for building HTTP services that can be consume by a broad range of clients including browsers, mobiles, iphone and tablets. It is very similar to ASP.NET MVC since it contains the MVC features such as routing, controllers, action results, filter, model binders, IOC container or dependency injection. But it is not a part of the MVC Framework. It is a part of the core ASP.NET platform and can be used with MVC and other types of Web applications like Asp.Net WebForms. It can also be used as an stand-alone Web services application. Why Asp.Net Web API (Web API) ? Today, a web-based application is not enough to reach it's customers. People are very smart, they are using iphone, mobile, tablets etc. devices in its daily life. These devices also have a lot of apps for making the life easy. Actually, we are moving from the web towards apps world. So, if you like to expose your service data to the bro...

Difference between WCF and Web API and WCF REST and Web Service

Difference between WCF and Web API and WCF REST and Web Service The .Net framework has a number of technologies that allow you to create HTTP services such as Web Service, WCF and now Web API. There are a lot of articles over the internet which may describe to whom you should use. Now a days, you have a lot of choices to build HTTP services on .NET framework. In this article, I would like to share my opinion with you over Web Service, WCF and now Web API. For more information about Web API refers What is Web API and why to use it ?. Web Service It is based on SOAP and return data in XML form. It support only HTTP protocol. It is not open source but can be consumed by any client that understands xml. It can be hosted only on IIS. WCF It is also based on SOAP and return data in XML form. It is the evolution of the web service(ASMX) and support various protocols like TCP, HTTP, HTTPS, Named Pipes, MSMQ. The main issue with WCF is, its tedious and extensive config...