Welcome to this review of Web API, the 8th module of the Pluralsight course One ASP.NET From Scratch by Jesse Liberty and Jeff Fritz.
Jeff Fritz is a Program Manager for Microsoft in the ASP.NET and Azure Developer Experience teams.
Currently, he leads the NuGet team and manages the MSDN Web Developer Tools blog.
Prior to joining Microsoft, he was a Microsoft MVP, ASPInsider, INETA Community Champion and Developer Advocate for Telerik.
Also in this series:
Jeff gives a quick introduction to REST here, teaching us that REST is Stateless, Cacheable, and embraces the HTTP protocol.
For an in depth understanding of REST, see REST Fundamentals by Howard Dierking.
Jeff also describes some of the features of the modern programming model.
First Web API Demo
Jeff creates an ASP.NET project with the Web API template, and adds the Serialization framework.
In Product.cs we see that we specify properties as Data Members with the [DataMember] attribute.
We see in ValuesController that we are inheriting from ApiController. This is an easy way to distinguish this from a MVC controller.
This controller has methods for each of the HTTP verbs: Get, Post, Put and Delete.
We see an example of how we can use Fiddler‘s Compose feature to build requests to run against our web server.
Jeff finds an improvement we can make to our API service: returning a HttpResponseMessage with a 201 created status.
We can also return the location of where our consumers products were stored, in the HTTP header.
We can request our data in a particular format. For example:
Jeff demonstrates this in Fiddler.
If we want to deliver content in a different format, we can do this by implementing MediaTypeFormatter and registering with a config.Formatters statement.
Jeff demonstrates a simple text/csv formatter
For further details see Media Formatters in ASP.NET Web API 2.
Web API is one of the best designed pieces of software for developers to come out of Microsoft in recent years.
In this module of One ASP.NET From Scratch, Jeff offers Pluralsight subscribers an effective high level overview of Web API.
For more adventurous Pluralsight users, there are several full Pluralsight courses on Web API available:
- Web API v2 Security by Dominick Baier
- Building and Securing a RESTful API for multiple clients in ASP.NET by Kevin Dockx
- Building a Consistent RESTful API with OData V4 in ASP.NET by Kevin Dockx
- Building ASP.NET Web API OData Services by Brian Noyes
- Implementing an API in ASP.NET Web API by Shawn Wildermuth
If you would like to learn Fiddler, you can find recommended links on my Performance page.