20 August 2013

Productivity gains with the ServiceStack web framework

I am using the ServiceStack web framework with great success for almost a year and I want to expand  on why I have chosen it, its benefits and why it should be an essential part of  your software toolbox.


  Building modern web applications is challenging due to the rapid rate of innovation within the industry. JavaScript frameworks have gained momentum and a significant number of client side web frameworks are now replacing or at least complementing established server side web frameworks. The number of devices that connect to a web application is increasing together with the display form factors and input interface types.
  A good server side web framework should help in building a rich and versatile API, support the modern web and enforce a clean application architecture. It is a strategic asset and it should be chosen carefully.
 Fortunately there are quite a few .NET web frameworks that match these requirements - all open source and accepting community contributions:

  • community based - ServiceStack, OpenRasta, Simple.Web, NancyFx, FubuMVC, Oak;
  • provided by Microsoft - ASP.NET Web Api and ASP.NET MVC(with some extra components on top).

  At the time of my initial experiments with these frameworks(second half of 2012) I quickly found out that ASP.NET Web Api was missing important functionality out of the box: JSONP and CORS support, had only a handful of media formatters. You could either dig up some blog entries that provided some of the missing pieces or you could implement them yourself. The same thing was true for ASP.NET MVC: it needed open source components like Restful Routing to facilitate a resource oriented architecture and content negotiation.
  If I had to rely on open source community contributions and also spend development time to compensate for missing features shouldn't I check if one of the alternative web frameworks is a better choice? At this point I already looked at code samples and read blog entries for many of the web frameworks out there but getting code to work was the only way to do a proper assessment.
 All of the community based frameworks that I looked into were interesting and their authors invested a lot of effort and some even had a lot of community contributions. I think any of them could easily replace/complement the Microsoft ones, but in the end the ServiceStack framework came on top due to many factors that outweighed the benefits of the other frameworks:

  • Maturity - was around for a couple of years with consistent and frequent commits from its authors and its contributors;
  • Community involvement - over 200 contributors with a very active discussion group and lot of samples - I think it is the .NET project that has the biggest community involvement;
  • Excellent documentation: a very well written and thorough wiki, lots of blog entries, podcasts and screencasts;
  • Message based architecture - an interesting approach that contrasted with the rest of the frameworks;
  • One stop framework - covers all development needs while allowing to replace/enhance its parts. It embeds popular and fast open source components like Funq, MiniProfiler, FluentValidation and it also provides its own excellent components: serializers, cache clients, authentication, authorization, ORM.
  • Commercial support is on the way - this is a unique feature for ServiceStask and it is very useful if you need guaranteed support.

  Everything looks good on paper until you use it in anger. After implementing a couple of projects with ServiceStack I can now look back and report that:

  • I didn't had any problems/bugs: everything just worked really well;
  • It stayed out of my way: I was able to concentrate and work on application code with minimal infrastructure code required;
  • It works very well alongside ASP.NET and ASP.NET MVC: I was able to use ASP.NET for windows authentication and as an application shell while relying on ServiceStack for API functionality;
  • Very useful for building resource oriented applications: the message based architecture really shines by helping you to think in terms of routes and data transfer objects for each request and response;
  • It works very well with JavaScript applications and AngularJS: if your API is resource oriented than it will work seamlessly with the AngularJS ngResource component;
  • The one stop framework is the biggest productivity gain: rather than chasing libraries and best practices you can use the built in functionality. The whole framework is based on programming best practices and proven design patterns and if you grow out of something you can easily replace it;
  • It helps build testable applications: I found the message based architecture a great benefit for creating outside-in tests. You can start by defining a request and a response class and build your test method starting with just that. You can then write your assertions and start making your test gradually pass by implementing the rest of the functionality.

  By using a framework that does what described on its wiki I could get my code delivered as expected - no hidden surprises. Thanks to the work of its authors and its contributors ServiceStack is a feature rich and a reliable modern web framework. It is a benchmark for all the other frameworks and if you want to build modern web applications with minimal effort you should give it a try.

NOTES:

2 comments:

Aharon Koss said...

Alex,

I've developed a web app with service stack. You book was really helpful. I'm struggling to come up with a way to reset a user's password. Do you have any recommendations how to do this?

Thanks.

Aharon Koss

Alexandru Vasile Pop said...

Hi Aharon,
If you could not resolve your problem using the ServiceStack wiki you can now use the new "ServiceStack 4 Cookbook" for further information. There is a chapter there "Security and Authentication" that has a recipe for resseting user passwords. Even if you use ServiceStack 3 you might find a solution there.