Adding HTTP HEAD support to ASP.NET Web API
HEAD HTTP verb is defined in RFC 2616 as “identical to GET except that the server MUST NOT return a message-body in the response.” As such you can think of it as a twin brother of GET.
There are a lot of use cases for HEAD: pinging without the overhead of transferring data, or simply requesting information about the size of a resource (which can be used to provide download progress bar), just to name a few.
Unfortunately, out of the box, ASP.NET Web API doesn’t provide a mechanism of supporting HEAD or coupling GET & HEAD.
We can work around that.
SignalR, Filters and ServiceStack
ASP.NET Web API and Protocol Buffers
Protocol Buffers are a super efficient and very flexible way of serializing structured data. Developed at Google, provide the developers lightspeed serialization and deserialization capabilities.
There a handful of .NET implementations, the most popular one, called protobuf-net, created by Marc Gravell from StackExchange. On top of that library, WebApiContrib project has a Web API Protocol Buffers formatter ready for you to plug in.
More after the jump.
SignalR, ActionFilters and ASP.NET Web API
There have been quite a few examples circulating on the web on how one would use SignalR together with Web API. It all started after Brad Wilson had a great example on calling SignalR from API controllers at NDC Oslo 2012.
Even on this blog we looked at calling SignalR from Web API ITraceWriter to provide realtime tracing capabilities.
How about, to avoid any controller-level noise, messaging the connected SignalR subscribers from ActionFilters? While this approach might not be applicable in all scenarios, when it is, I think it could provide a nice layer of separation.
More after the jump.
But I don’t want to call Web Api controllers “Controller”!
A friend of mine was recently complaining about how Web API controller centric approach doesn’t really make sense, and that he prefers feature-oriented endpoints. While - in all honesty - I am not sure what he means by that, it got me thinking. Maybe, if we didn’t have to suffix Web API controllers “Controller”, that would make him happy?
More after the jump.
Building Web API Visual Studio support tools with Roslyn
In my humble opinion, Microsoft Roslyn is one of the most exciting things on the .NET stack. One of the many (MANY) things you can do easily with Roslyn, is write your own development-time code analysis tools.
We have talked about Roslyn scripting capabilities on this blog before (twice actually). Let’s look at code analysis today and see how we could built tools that could help Web API developers build nice clean HTTP services.
More after the jump.
Building real time applications for any client with Azure Mobile Services & Pusher
Azure Mobile Services is definitely one of the coolest technologies in the Azure family. One of the issues however, has been that it only has client libraries for Windows 8, iOS and Android, making it a bit more difficult for developers targeting other platforms (also web browsers!) to take advantage of its capabilities.
A while ago, I blogged about how to work around that - by using ZUMO REST API. However, you still didn’t have access to one of the nicest features of ZUMO for mobile devices - and that is push notifications. That changed recently, when ZUMO announced a partnership with Pusher, to provide push notifications for virtually any client.
Additionally, the team recently released another cool feature - scheduled tasks (cron jobs). Let’s see how you can use it all together to quickly build a realtime service.
More after the jump.
Adding Request.IsLocal to ASP.NET Web API
I was recently asked how to filter out local requests in Web API. Indeed, one of the more useful things that developers got used to work with in traditional ASP.NET (and the System.Web.dll) was the ability to quickly check if a given request is a local one or not - by simply calling the IsLocal boolean property on HttpRequest.
This has been omitted from HttpRequestMessage in the new HTTP object model, around which Web API is built, but Web API still keeps track of that information under the hood, so you can easily write a simple extension method to bring back the old familiar syntax.
More after the jump.
Magical Web API action selector – HTTP-verb and action name dispatching in a single controller
If you follow Web API on User Voice or track Web API issues on Codeplex, you’d probably know that one of the most popular requested features of Web API is to allow the developers to combine HTTP verb action dispatching (default one), with action-name based dispatching in a single controller.
The rationale is very obvious, and I’m pretty sure there is not a single Web API developer in the world, who hasn’t run into this problem - by not being allowed to combine these, whenever you want to create a nested resource, you need to add a new controller and manually register a funky nested route to facilitate it.
Let’s create a custom action selector to solve this.
Easy ASP.NET Web API resource updates with Delta
One of the great features of the Microsoft ASP.NET WebAPI OData package (which you can grab as prerelease from Nuget, and which will soon, in next release cycle, become part of Web API core) is a little dynamic proxy object called Delta
It allows you to perform ridiculously easy mapping of properties between the model obtained from the database and the model passed by the client - thus facilitating all kinds of update scenarios your application may encounter.
Unfortunately, it will not work for you - unless you commit to ODataMediaTypeFormatter and all the extravaganza related to OData. What if you want to use the traditional API formatters, but still leverage on the power of Delta
Let’s have a look at how you can perform really smooth full (PUT) and partial (PATCH) updates of your resources in Web API.
About
Hi! I'm Filip W., a software architect from Zürich 🇨🇭. I like Toronto Maple Leafs 🇨🇦, Rancid and quantum computing. Oh, and I love the Lowlands 🏴.
Recent Posts
- 2024/12/12, Generating OpenQASM from Q# code
- 2024/11/22, Simplifying the AI workflow: Access different types of model deployments with Azure AI Inference
- 2024/11/15, Strathweb Phi Engine - now with Safe Tensors support
- 2024/10/25, How GPT-4o-mini can be simultaneously 20x cheaper and 2x more expensive than GPT-4o
- 2024/10/14, Speech-based retrieval augmented generation (RAG) with GPT-4o Realtime API
Categories
- ai (16)
- ai search (5)
- apache cordova (1)
- asp.net 5 (17)
- asp.net core (47)
- asp.net mvc (35)
- asp.net mvc 6 (7)
- asp.net vnext (6)
- asp.net web api (96)
- astronomy (1)
- autogen (1)
- azure (22)
- azure service bus (1)
- azure-devops (1)
- benchmark dotnet (1)
- bing maps (1)
- blazor (2)
- c plus (2)
- c-sharp (155)
- cryptography (5)
- csharp (5)
- csharp 10 (2)
- dnx (3)
- dotnet-cli (2)
- dotnet-script (11)
- duende (4)
- editorconfig (1)
- entity framework (2)
- espn api (2)
- events (1)
- ffi (4)
- fsharp (1)
- git (1)
- glimpse (1)
- html5 (4)
- identity server (2)
- iis (2)
- il (1)
- intro to qc (19)
- ios (5)
- javascript (9)
- jquery (4)
- jquery mobile metro (1)
- katana (2)
- kindle (1)
- knockout.js (8)
- kotlin (2)
- last.fm api (2)
- linq (1)
- mac (2)
- macos (1)
- mathematica (1)
- msbuild (3)
- mvc core (3)
- nancy (2)
- native (1)
- net (141)
- net 5 (3)
- net 6 (5)
- net 7 (7)
- net 8 (3)
- net 9 (1)
- net core (49)
- net sdk (2)
- ninject (2)
- odata (4)
- oidc (2)
- omnisharp (13)
- openai (11)
- osx (2)
- owin (5)
- phi (4)
- php (1)
- python (1)
- q-sharp (35)
- qir (3)
- quantum computing (39)
- roslyn (30)
- rust (5)
- scriptcs (11)
- scripting (9)
- security (8)
- servicestack (2)
- signalr (8)
- swift (8)
- testing (5)
- twitter boostrap (1)
- typescript (1)
- visual studio (4)
- visual studio code (11)
- wasi (3)
- wasm (3)
- windows phone 7 (1)
- wordpress (1)
- wpf (2)