Which is better for building an API for my website: MVC or Ado.net data services?
Asked Answered
I

3

5

I have a website built with MVC, and now I want to build an API for this website, to let users to use this API to implement different website, web services, plugins and browser extensions.

I went through this article but didn't get yet which to use.

General info about the API I want to build:
The user of the API will have a key user name and password to be able to use the API.
API will let users add content to my DB after validating this data.
API will let users upload images to my server.
API need to have friendly URLs.

Which technology will fit in my case?

Also will help me decide is to know what is the technology behind stackoverflow API?

Ideomotor answered 3/7, 2011 at 20:49 Comment(3)
if you already have a website built in ASP.NET MVC, the step to OData and WCF Data Services (what you call "ADO.NET Data Services") incurs a horrible overhead unless you specifically want to target OData and/or take advantage of other WCF Data Services particulars. Adding a RESTful API layer in MVC is trivial.Flavorsome
+1 to the above comment, totally agree.Libre
Ok, what about stackoverflow.com, it is mvc, do you know what is its api built with?Ideomotor
A
8

Try WCF Web Api. It has got all the cool stuff to create good RESTFul api, and it satisfies all your requirements.

  • You will use basic or some custom http authorization, simple as that.
  • You will expose very basic urls for creating data, validate and return response, trivial.
  • RESTFul means friendly url -s.

The general idea is that this library gives you strong manipulation options from the very start of request till its response back. This is the main HTTP api for .NET Framework and WCF and it continues its evolution.

Atreus answered 4/7, 2011 at 5:44 Comment(1)
According to the FAQ, it is not yet allowed to be used in production environments.Valora
R
3

Have you considered instead using OpenRasta?

Its clean, ReSTful approach makes it ideally suited to developing web-based APIs in .NET.

Rambutan answered 27/9, 2011 at 20:25 Comment(0)
O
1

Unless you have a very compelling reason to use WCF, why not just expose your data through the ASP.NET MVC site. You can easily return JSON or any other non-HTML data format that suits your needs from within ASP.NET MVC.

Depending on how similar the interface between your web site and your API need to be you might be able to use your existing controllers/actions or create new ones. In theory if the HTTP request indicates "application/json" you can just return JSON to those requests and be done...but in practice you will probably need to tweak the end points (controllers/actions) to make them friendly to your new consumer (other developers targeting your API)

WCF is very good and feature rich but not everybody is familiar with it. You might incur a learning curve getting a good understanding of it. Again, if there is a very valid reason for it then it's worth it, but from what you are describing you will probably be just as good with plain ASP.NET MVC.

Ossified answered 26/9, 2011 at 15:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.