为我的网站构建 API 哪个更好:MVC 或 Ado.net 数据服务?
我有一个用MVC构建的网站,现在我想为这个网站构建一个API,让用户使用这个API来实现不同的网站、Web服务、插件和浏览器扩展。
我经历了这个文章 但尚未得到使用哪个。
有关我要构建的 API 的一般信息:
API 的用户将拥有一个关键的用户名和密码才能使用该 API。
API 将允许用户在验证此数据后将内容添加到我的数据库。
API 将允许用户将图像上传到我的服务器。
API 需要有友好的 URL。
哪种技术适合我的情况?
另外帮助我决定的是了解 stackoverflow API 背后的技术是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试 WCF Web Api。它拥有创建良好 RESTFul api 的所有很酷的东西,并且它满足您的所有要求。
总的想法是,这个库从请求开始到响应返回,为您提供强大的操作选项。这是 .NET Framework 和 WCF 的主要 HTTP API,并且仍在不断发展。
Try WCF Web Api. It has got all the cool stuff to create good RESTFul api, and it satisfies all your requirements.
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.
您是否考虑过使用 OpenRasta ?
其简洁、ReSTful 方法使其非常适合在 .NET 中开发基于 Web 的 API。
Have you considered instead using OpenRasta?
Its clean, ReSTful approach makes it ideally suited to developing web-based APIs in .NET.
除非您有非常令人信服的理由使用 WCF,否则为什么不直接通过 ASP.NET MVC 站点公开您的数据。您可以从 ASP.NET MVC 中轻松返回 JSON 或任何其他适合您需求的非 HTML 数据格式。
根据您的网站和 API 之间的接口需要的相似程度,您可以使用现有的控制器/操作或创建新的控制器/操作。理论上,如果 HTTP 请求指示“application/json”,您只需将 JSON 返回到这些请求即可完成...但实际上,您可能需要调整端点(控制器/操作)以使它们对您的新请求友好消费者(针对您的 API 的其他开发人员)
WCF 非常好且功能丰富,但并不是每个人都熟悉它。为了充分理解它,您可能会遇到一个学习曲线。再说一次,如果有一个非常有效的理由,那么它是值得的,但根据您所描述的内容,您可能会使用普通的 ASP.NET MVC 一样好。
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.