3

我目前正在启动一个大型 Web 应用程序项目,其中一个要求是我可能需要允许 iOS 和 Android 应用程序与我的应用程序交互,我认为最好的解决方案是创建一个 RESTful API 并拥有与它的 Web 应用程序接口。然而,我做前端开发的同事不熟悉使用 javascript 框架,例如backbone.js(我知道更多的库)、ember.js 或 angular.js。由于我们使用的是 asp.net,我认为我可以使用 asp.net MVC 处理身份验证和路由,根据路由提供单独的视图,并且他只能处理数据操作,但是,我似乎不知道了解如何将路由与 javascript 框架分开,我研究了 ember。

有谁知道如何在不需要路由的情况下实现数据操作?

4

2 回答 2

10

What you are describing is generally called API oriented architecture, meaning you have a RESTful service on a back-end and rich client-side application on front end.

The point is, it basically does not matter what technology you pick up on server. It could be anything: ASP.NET MVC, Web API, Express.js or Django. As soon as it's really RESTful and pure. By purity I mean, it deals only with data, no serving of HTML or something.

Server just specify the interface you work with data,

GET   /invoices        // get all invoices
GET   /invoices/:id    // get invoice by id
POST  /invoices        // post new invoice

If you confident with .NET, WebAPI is probably good choice. Typically you would prefer JSON output, WebAPI could handle content negotiation for you.

Now, the client job is to consume the API data and dynamically create HTML in browser. A lot of options now: Backbone.js, Angular.js etc.

Please be aware: client side routing and server side routing are completely different things.

Server side routing: routes particular HTTP request to particular controllers action (or any function).

Client side routing: detects the URL change and triggers corresponding JavaScript function to handle change. Client side routing is vital for SPA (single page applications). You can find a bit more information on SPA on that blog post.

于 2013-08-21T08:32:57.973 回答
1

查看KnockoutJS,它允许您使用 ASP.NET MVC 进行路由或其他 JavaScript 库,如sammy.js(仅用于路由)或Durandal(用于路由和导航)。

注意:Durandal 版本 1 内部使用了 sammy.js,但版本 2 有一个自定义路由引擎,不再使用 sammy.js。

于 2013-08-21T03:37:34.070 回答