1解MVC 4个Web API +应用程序 [英] MVC 4 web api + application in 1 solution

查看:132
本文介绍了1解MVC 4个Web API +应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是疯狂地在许多方面,但我只是用MVC开始由于ASP .NET网页API看起来真的很有趣。

this is probably daft in many ways but I'm just starting with MVC as the asp .net web api looks really interesting.

一想到可以在网络API也可以作为前端的互联网应用?我猜测,答案是'不',但它可以节省大量的时间以某种方式获得API会在同一个地方前端的工作,有什么其他的选择 - 创造的API 1项目和另一个用于前端?

Just thinking can a 'web api' also serve as a front end internet application? I'm guessing that the answer is 'no' but it could save lots of time to somehow get the API working with the front-end in the same place, what's the other option - create 1 project for the API and an another for the front end?

推荐答案

由于MVC分离业务逻辑视图,并使用REST进行数据检索,你可以建立一个MVC应用程序,然后就记录如何其他应用程序的API标准可以与您的应用程序界面。

Since MVC separates the view from the business logic and uses REST for data retrieval, you can build a MVC application and then just document the API standard for how other applications can interface with your application.

例如,您的应用程序有一个称为小工具视图。幕后的观点实际上调用 http://myapplication.com/gadgets/1 拿到第一可用小工具的页面,然后遍历它们在HTML格式的数据显示到浏览器。在现实中,因为 http://myapplication.com/gadgets/1 应该总是返回小工具的第一页,您可以在API文档中说调用 http://myapplication.com/gadgets/1 返回第一个小工具的页面。如果我调用应用程序,那么所有我必须做的就是把这个网址,并分析出的结果显示。

For example, your application has a view called Gadgets. Behind the scenes the view is really calling http://myapplication.com/gadgets/1 to get the first page of available gadgets and then loops through them to display the data in html format to the browser. In reality since http://myapplication.com/gadgets/1 should always return the first page of gadgets, you can say in your API documentation that calling http://myapplication.com/gadgets/1 returns the first page of gadgets. If I am the calling application then all I have to do then is call this url and parse out the result for display.

这是MVC的,如果你正确地执行它的美丽。

This is the beauty of MVC if you implement it correctly.

这篇关于1解MVC 4个Web API +应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆