简体   繁体   English

会话变量和RESTful api

[英]Session variables and RESTful api

We are in the process of gradually implementing REST services for our web application. 我们正在为Web应用程序逐步实现REST服务。 Currently, the application is in old procedural style type app. 目前,该应用程序是旧的程序样式类型的应用程序。

The new app will be in html5 with back end implemented in CF10 REST api calls to cfc`s returning JSON formatted objects. 新的应用程序将在html5中,后端在CF10 REST api调用中实现,cfc返回JSON格式的对象。

We need to pass SESSION variables to the REST cfc's through jquery calls. 我们需要通过jquery调用将SESSION变量传递给REST cfc。 Is there way to avoid putting SESSION variables as arguments to jquery calls? 有没有办法避免将SESSION变量作为jquery调用的参数? All the REST cfc's are located in the web root of Coldfusion10 so, SESSION scope is not accessible to REST cfc's. 所有REST cfc都位于Coldfusion10的Web根目录中,因此REST cfc不能访问SESSION范围。

Thanks 谢谢

I found the following documentation about RESTful services in ColdFusion . 在ColdFusion中找到了有关RESTful服务的以下文档。 See bullet 4 in particular: 特别参见子弹4:

REST architectural principles: REST架构原则:

A REST-based application follows some architectural principles: 基于REST的应用程序遵循一些架构原则:

  1. Resource identification : In REST-based architecture everything is a resource. 资源识别 :在基于REST的架构中,一切都是资源。 You must identify each of these resources with an URI. 您必须使用URI标识每个资源。 In ColdFusion, you can make the functions you define in a CFC available as REST resources and you can access them using an URI. 在ColdFusion中,您可以将在CFC中定义的函数作为REST资源使用,并且可以使用URI访问它们。
  2. Uniform and constrained interface : Every resource in a RESTful application should support HTTP common operations ie the resources should be able to handle HTTP protocol methods – GET , PUT , POST and DELETE . 统一和受约束的接口 :RESTful应用程序中的每个资源都应支持HTTP公共操作,即资源应该能够处理HTTP协议方法 - GET,PUT,POST和DELETE。 In ColdFusion, you can access the resources (functions) via HTTP; 在ColdFusion中,您可以通过HTTP访问资源(函数); each of these resources supports HTTP verbs. 每个资源都支持HTTP谓词。 Depending on the verb specified in the request, the corresponding resource is invoked. 根据请求中指定的谓词,将调用相应的资源。
  3. Representation oriented : REST allows resources to have different representation – plain, HTML, XML, JSON, and so forth. 面向表示 :REST允许资源具有不同的表示形式 - 普通,HTML,XML,JSON等。 A client can request a specific representation via the HTTP protocol. 客户端可以通过HTTP协议请求特定的表示。 HTTP provides a simple content-type negotiation protocol between the client and the server. HTTP在客户端和服务器之间提供简单的内容类型协商协议。 For example, an AJAX application may need data in JSON format, where as a Java application may need it in XML format. 例如,AJAX应用程序可能需要JSON格式的数据,而Java应用程序可能需要XML格式的数据。
  4. Stateless communication : In REST, the server doesn't store the client session data. 无状态通信 :在REST中,服务器不存储客户端会话数据。 However, many techniques exist to exchange state information such as URI rewriting, cookies, and hidden form fields. 但是,存在许多技术来交换诸如URI重写,cookie和隐藏表单字段之类的状态信息。 Also, for encryption, you can use REST on top of HTTPS. 此外,对于加密,您可以在HTTPS之上使用REST。

Also found these discussions about it here on StackOverflow: 还在StackOverflow上找到了关于它的这些讨论:

Way to maintain a session in a REST application 在REST应用程序中维护会话的方法

Website based on REST in ColdFusion 基于RESTF的ColdFusion网站

maintaining session in REST web service 在REST Web服务中维护会话

Do sessions really violate RESTfulness? 会话真的违反了R​​ESTfulness吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM