Supporting the OPTIONS verb in ASP.NET Web API

ASP.NET Web API controllers support only four HTTP verbs by convention: GET, PUT, POST and DELETE. The full list of existing HTTP verbs is more extensive though. One of those unsupported verbs which can be particularly useful for API discovery and documentation is the OPTIONS verb. The OPTIONS method represents a request for information about the communication options available on the request/response chain identified by the Request-URI. This method allows the client to determine the options and/or requirements associated with a resource, or the capabilities of a server, without implying a resource action or initiating a resource retrieval. ...

September 2, 2012 · 3 min · Jef Claes

Is serialization really that expensive?

While wading through an exotic codebase, I stumbled upon a static class named Convert. This class contained somewhere around 2700 (non-generated) lines of code, where each method manually converted some object to a simple textual representation. These methods were then used to convert requests and reponses to and from a remote third party service before logging them to the database for auditing reasons. public static class Convert { public static string PaymentRequest(PaymentRequest req) { var sb = new StringBuilder(); sb.Append("Reference: " + req.Reference + " - "); sb.Append("NumberOfLicenses: " + req.NumberOfLicenses + " - "); sb.Append("PricePerLicense: " + req.PricePerLicense + " - "); sb.Append("CardNumber: " + req.CardNumber + " - "); sb.Append("Address: " + req.Address); return sb.ToString(); } } My first thoughts were something along of the lines of “What the.. this is insanely stupid code.” This must be a PITA to maintain and be extremely error-prone. Looking at the solution now, it looks simple enough to move that to some infrastructure and have the conversion done by something more generic. Serializing to JSON comes to mind; interpretable by man ánd machine. ...

August 22, 2012 · 3 min · Jef Claes

My learning resources distilled

I have picked up a few new tools this summer (MongoDB, NancyFx and WebAPI), and it occurred to me that I’ve built certain habits these last few years in how I make use of all the learning resources out there. I tried to identify all of them, to then categorize them, to finally order them according to in which phase of my study process I use them. The written and spoken word The first thing I look for online is documentation. It might be a coincidence, but all the documentation I found for these three tools was excellent. It seems obvious, now more than ever, that the early adaptation of new tools can be proportional to the quality of their documentation. ...

August 19, 2012 · 4 min · Jef Claes

Finito

With this last post, our trip to Italy has come to an end. We have spent these last few days practicing several indispensable tourist activities: testing the ice cold lake water, to wriggle between other sunbathers on the packed beach right after, exuberant eating and drinking, reading novels, and sauntering between prullaria shops. Fortuitously, one of our last evenings here was upgraded by fireworks over an already moonlit Lake Garda. This outlying location gave the fireworks show an extra notch. With each firework rocket, the pitch dark beach was illuminated for a few seconds. With each bang, the sound echoed over the mountains, making the water ripple to strand in the pebble beach eventually. ...

July 30, 2012 · 1 min · Jef Claes

Milano

After Venice on Wednesday, we decided to stay in Torbole for a relaxing hike yesterday. As it turned out, the hiking trail that was described in the brochures as suitable for all and with a duration of 1h20, in reality took us 2h30 and sour calves to complete. The views of the lake’s valley and its school of windsurfers defying the wind were worth the sweat though. Arriving at the endpoint, and discovering that we had to wait over an hour for the bus to take us back, we stumbled upon one of the best hidden lake side terraces we’ve seen yet. ...

July 27, 2012 · 2 min · Jef Claes

The Floating City

Yesterday we cruised along the eastern coastline of Lake Garda. Plan A was to visit Malcesine and take the cableway up to the top of Monte Baldo, but since the line at the ticket center resembled one of a Justin Bieber concert, we skipped the cableway. Maybe we’ll give it another try later this week, but then earlier in the day. We continued our journey along the coast, passing past several genuinely picturesque villages. We stopped in Garda for an elaborate lake side lunch, before continuing to our last destination that day, Sirmione. There we visited the medieval castello Scaligero and after climbing the numerous steps inside the castle, we rewarded ourselves with an oversized typical Italian gelato. ...

July 26, 2012 · 2 min · Jef Claes

Ferrari red. Lamborghini yellow.

After 14 hours and 34 minutes in the car, driving 1148km, over the German autobahn, swerving Austrian roads, and the Italian autostrade, defying overwhelming hail storms, roadwork and miles long tunnel congestions, we arrived at Torbole, Italy. Torbole is a small village, nestled between the mountains, right at the edge of Lake Garda. While the lakeside view is astonishing, you have to pick the right time to truly experience it. In the daytime, the village is overwhelmed by tourists; miles long rows of cars queue to enter the village, pizzerias and ristorantes on every corner, Germans galore. This doesn’t take away that this location is a great launching point to visit other places in northern Italy though. ...

July 24, 2012 · 2 min · Jef Claes

Should I unit- or integration test my ASP.NET Web API services?

Over the last two weeks, preparing for a talk, I have been doing some research on ASP.NET Web API. After working my way through the API, and the implementation of certain features, I looked at testing. Similar to ASP.NET MVC, Web API allows you to create relatively small building blocks, which can replace parts of, or be added to an existing default global setup. This makes it possible for us to test each component in isolation: controllers, dependency resolvers, filters, serialization, type formatters, messagehandlers and routing. ...

July 15, 2012 · 4 min · Jef Claes

HtmlHelper to generate a top-level menu for areas

Last week, we had to set up a new ASP.NET MVC web application, using a somewhat customized Twitter Bootstrap build. Because the application has multiple functional contexts, we divided it in multiple parts using areas. Since these areas were a one-to-one mapping with the top-level menu items, we tried abstracting the creation of the menu items, ánd the management of setting the active item, into an HtmlHelper. Let’s say, for this example, that we have six areas: Images, Maps, Play, Search, Video and Blog, and we want to render a list item for each one of them. ...

July 8, 2012 · 3 min · Jef Claes

On crime and document stores

Having worked with several storage paradigms over these last few months - from flatfiles, to NoSQL, to the big enterprisey relational databases -, I have spent plenty of time trying to make sense of all the options out there. It wasn’t until I watched one of the last episodes of The Wire season 3 that I had an epiphany regarding modeling data in document stores. Yes, I know, I tend to take those things home with me. ...

July 1, 2012 · 5 min · Jef Claes