October, 2012

Clean up your Web API controllers with model validation and null check filters

Because filters are your friends

Regardless of what kind of applications you build with Web API, you are bound to write a lot of similar code in many of your actions – to check if the model is valid and to check if the submitted object is null.

This creates unnecessary noise and repetition. In this short blog post, let’s have a quick at how you can delegate this kind of repetitive logic to Web API filters.

More after the jump.

Continue reading

Send text messages (SMS) from Web API using Azure Mobile Services

Because ZUMO is becoming super awesome

Few weeks ago, I blogged about using Azure Mobile Services in your Web API applications and I think I managed to convince some of you that ZUMO with its REST-style API is really useful and super easy to work with.

The guys at Azure Mobile Services are not slowing down at all. Today Scott Gu announced a whole new super cool set of upgrades, and one of the coolest features is the integration to Twillio and the ability to send text messages (SMS) directly from the ZUMO script.

Let’s go ahead and extend our previous ZUMO example (managing a list of sports team) with SMS messaging.

Continue reading

Remote printing with ASP.NET Web API in Windows Service

Because you don't need a print server!

We all have different devices at home, right? So I had this idea, why not make a small Web API driven Windows service to sit on my main machine, to which I can send documents, which in turn will send them to the printer and print out. Sounds great doesn’t it?

Since Web API self host can be without any problems hosted as Windows Service, the whole application is really simple to put together. Let’s do that.

Continue reading

Use Web API as a dynamic runtime Typescript compiler

Because you don't need to precompile Typescript

There’s been a lot of community buzz about Typescript recently – and rightfully so – as it solves a lot of Javascript’s issues, and despite being in its infancy, shows a tremendous amount of potential already.

One of the features (or side effects, depending on how you look at it) of Typescript, is that your are required to compile your code, to produce JS output. Sure, it is possible to dynamically compile Typescript in the browser (using its JS compiler), but that requires you to reference Typescript.js which is roughly 250 kB, and might be a tough pill to swallow.

However, using the ASP.NET Swiss army knife called Web API, and an approach we already disuussed on this blog before, let me show you how you can quite smoothly leverage on Web API pipeline to dynamically compile your Typescript code into Javascript at runtime.

More after the jump.

Continue reading

Scripting Web API self host with Roslyn CTP – Part 2

Because you can build your own interactive compiler/parser

This is part two of the series – if you haven’t read part one check it out before proceeding.

Last time we did some cool stuff with using C# script files to instantiate a working Web API server – by executing them with RCSI and C# interactive window.

In part two, let’s use Roslyn to build our own scripting application (custom C# console), which will act as an input window for the user; user will be able type C# code that’s supposed to be executed and run it (something that services such as Compilify offer). We will expose Web API assemblies in that context, allowing the user to type in the code required for the Web API server to be run.

More after the jump.

Continue reading