Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What framework to use for RESTful Services in .net

Tags:

I know that similar questions have been asked, but most of them are out of date. So here we go again :). I need to implement a complete REST service layer for our application. The problem that i have is which framework would be the best to solve this problem. I just need a nice framework that lets me focus on the problem and not on the REST or whatever is required. Authentication is a required feature. Here are some of my ideas; what do you think?

  • WCF: In my opinion this is a overloaded framework that makes things complicated.
  • ServiceStack: Seems to be a nice, lightweight, open source alternative. But what if they decided to stop development?
  • Custom implementation using asp.net mvc such as this, but why reinvent the wheel?
like image 209
raisr Avatar asked Jul 08 '11 06:07

raisr


People also ask

Which Microsoft framework is used to produce RESTful services?

Net framework 2.0, 3.0 or only beyond that. Here they have mentioned that Microsoft has added REST style services support to WCF in framework 3.5.

What is RESTful applications on the .NET framework?

A RESTful API is an architectural style for an application program interface (API) that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types, which refers to the reading, updating, creating and deleting of operations concerning resources.

Which .NET core components would you use to build a cross platform RESTful web service?

ASP.NET Core makes building RESTful services easy and comfortable.


2 Answers

I originally started ServiceStack because of the inefficiency (development and runtime) and friction imposed in creating web services with alternative .NET frameworks.

3-4x Faster Json Serialization than MVC

ServiceStack has a strong focus performance as we believe it provides the best end-user UX which is why it comes in-built with a strong set of Caching providers including the fastest JSON Serializer for .NET - 3-4x times faster than the serializers shipped with .NET and MVC (its default JavaScriptSerializer is the slowest in .NET). For max performance there's no runtime reflection or Regular Expressions used. It employs smart non-linear Route matching and you're recommended to use the much faster built-in Caching providers to work around the poor performance of ASP.NET's Session.

Focused on typed, iterative, code-first development

ServiceStack lets you develop strong-typed web services promoting best practices out-of-the-box using the minimum amount of code and automatically without any code-gen, config, pre/post build-steps, etc.

Example of a simple Hello World service:

public class Hello { public string Name { get; set; } } public class HelloResponse { public string Result { get; set; } }  public class HelloService : IService  {     public object Get(Hello request)      {         return new HelloResponse { Result = "Hello, " + request.Name };     } } 

With just these classes, all your web services are automatically made available in a variety of different formats (JSON, XML, JSV, CSV, SOAP) all out-of-the-box with zero effort.

Example of Strong Typed Client API using C#:

var client = new JsonServiceClient("http://localhost/Service"); var response = client.Send<HelloResponse>(new Hello { Name = "World!" }); 

JavaScript example using jQuery:

$.getJSON("http://localhost/Service/hello/World!", function(r) {     console.log(r.Result); }); 

Development friendly

Because visualizing web services is important when iteratively developing web services, the default Content-Type when viewing web services in a browser is a human friendly JSON HTML5 Report format (also available stand-alone at http://ajaxstack.com/jsonreport/) which enables you to visualize the response of your web services in a glance.

You also get an automatically generated metadata page (that you can annotate with your own custom description) which serves as a great way to document your web service API.

But what if they decided to stop development

As the creator of ServiceStack I don't see myself abandoning development in the foreseeable future. I build systems with it daily simply because I find it's a cleaner, faster, more productive framework to develop with.

Promotes best-practices

There are very few .NET web services frameworks that promote a DTO-first message-based architecture enabling the Service Interface pattern - A web services best-practice commonly seen in the Java ecosystem making it easy to develop batch-full coarse grain SOA-based web services.

There is 0 risk it will be abandoned in favour of another .NET web service framework. Simply because we don't believe any other .NET framework actively promotes web services best-practices (i.e. DTO / Remote Façade and Service Interface patterns) and a primary focus on performance.

But even so as an Open Source project with nearly 20 contributors, this fear is mitigated. How many proprietary, closed-source frameworks have MS abandoned and forced everyone to move onto a successor? Open source software evolves, it doesn't get abandoned and rewritten.

The entire source code for ServiceStack lives under http://github.com/ServiceStack there is no lock-in and GitHub makes it easy for anyone to fork and continue development as many have already done.

Works everywhere

Finally, ServiceStack can run on any ASP.NET host in IIS 6/7 on Windows or Linux/OSX using Mono. It also supports a stand-alone HttpListener host allowing you to run it without a web server, i.e. embedded in any Console or Windows application, inside a Windows Service and has even hosted inside a MonoTouch iPhone application.

like image 64
mythz Avatar answered Sep 20 '22 05:09

mythz


Been playing with Nancy myself lately and I'm also considering Manos de Mono. Here's the an example from the home page on Nancy.

public class HelloModule : NancyModule {     public HelloModule()     {         Get["/"] = parameters => "Hello World";     } } 
like image 41
kenny Avatar answered Sep 21 '22 05:09

kenny