单页应用和RESTful API [英] Single Page Application and RESTful API

查看:275
本文介绍了单页应用和RESTful API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个真正的RESTful API,利用超媒体,以便客户端只依赖于服务器提供的动态超媒体通过应用程序(称为的 HATEOAS

A real RESTful API leverages hypermedia so that clients rely only on dynamic hypermedia provided by server to navigate through the application (the concept known as HATEOAS)

这概念是很容易适用于Web应用程序,但你怎么把它应用到单页应用为正常的SPA内部管理自己的状态(而不依赖于服务器上就导航而言)?

This concept is easily applicable to web applications but how do you apply it to Single Page Application as SPAs normally manage their state internally (without relying on the server as far as navigation is concerned) ?

我的感觉是水疗不能充分利用RESTful API中或我错过了什么?

My feeling is that SPAs cannot fully leverage RESTful APIs or did I miss something ?

感谢

Riana

推荐答案

一个SPA的特殊性在于它提供了客户端,而不是构建的服务器上的,只是呈现在客户端上构建的UI更流畅的用户体验。

A SPA's particularity is it provides a more fluid user experience with the UI constructed on the client instead of being constructed on the server and just rendered on the client.

一个SPA不一定需要保持自己的状态,服务器仍然可以驱动HATEOAS的相互作用。对于SPA是驱动超媒体或以其他方式维护自己的状态并获得predefined资源,完全取决于应用程序。

A SPA doesn't necessarily need to hold its own state, the server can still drive the interactions with HATEOAS. For the SPA to be hypermedia driven or otherwise maintain its own state and access predefined resources, depends entirely on the application.

组合也能正常工作,例如像对SPA保持其自身的状态与其他正由服务器从动某些部分。在这个意义上,可以考虑例如分页结果。 SPA的可能会去一个特定的URL(具有资源的先验知识)来获得结果的列表,这些结果被分页。服务器嵌入结果中的链接,使客户可以将其定位到下一个和previous页(您通过超媒体应用服务器提供交互)。

Combinations can also work, like for example the SPA maintaining its own state for some parts with other being driven by the server. In this sense, consider for example paginated results. The SPA might go to a particular URL (having prior knowledge of that resource) to get a list of results, with those results being paginated. The server embeds links inside the results so that the client can navigate them to the next and previous pages (you interact with the application through hypermedia provided by the server).

我的感觉是水疗不能充分利用RESTful API中或我错过了什么?

My feeling is that SPAs cannot fully leverage RESTful APIs or did I miss something ?

正如我前面所说,这取决于你的应用程序。如果是有意义的应用程序中进行超媒体驱动的,那么就可以建成这样。在另一方面,如果它更有意义有SPA驱动器本身,然后迫使它HATEOS可能不是一个好主意。

As I said above, it depends on your application. If it makes sense for the application to be hypermedia driven, then it can be built like that. On the other hand, if it makes more sense to have the SPA "drive itself" then forcing HATEOS on it might not be a good idea.

这篇关于单页应用和RESTful API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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