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

穿精又带淫゛_ 提交于 2019-12-04 08:59:19

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.

Have you considered instead using OpenRasta?

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!