简体   繁体   English

如何在Delphi DataSnap REST服务器上映射自定义HTTP方法前缀

[英]How do I map custom HTTP method prefixes on a Delphi DataSnap REST server

RESTful services created with Delphi's DataSnap provide a default mapping of prefixes for exposed REST methods from the DataSnap server based on the HTTP method type. 使用Delphi的DataSnap创建的RESTful服务基于HTTP方法类型为DataSnap服务器中公开的REST方法提供了前缀的默认映射。 These are as follows: 这些如下:

HTTP Method type   Prefix       Example
GET                none         MyValue
POST               Update       UpdateMyValue
PUT                Accept       AcceptMyValue
DELETE             Cancel       CancelMyValue

The documentation states "The mapping pattern can be overridden. The user can override the mapping for each type based on class name and method name parameters." 文档声明“可以覆盖映射模式。用户可以根据类名和方法名参数覆盖每种类型的映射。” However, I have utterly failed to find any documentation on how to do this. 但是,我完全没有找到有关如何执行此操作的任何文档。 I want to change the prefix of my PUT from Accept to something else. 我想将PUT的前缀从Accept更改为其他内容。 How do I do that? 我怎么做?

I should note that another posting here on StackOverflow ( REST Datasnap override URI mapping ) attempts to answer this question by pointing out that TDSHTTPService has methods for performing this mapping. 我应该注意到,StackOverflow上的另一个帖子( REST Datasnap覆盖URI映射 )试图通过指出TDSHTTPService具有执行此映射的方法来回答这个问题。 That same post also references Marco Cantù's DataSnap white paper, which supposedly also describes how to do this. 同一篇文章还引用了MarcoCantù的DataSnap白皮书,该白皮书据说也描述了如何做到这一点。 That white paper says "You can customize these mappings by handling the four corresponding event handlers of the DSHTTPWebDispatcher component." 该白皮书说:“您可以通过处理DSHTTPWebDispatcher组件的四个相应事件处理程序来自定义这些映射。”

In RAD Studio XE, both the TDSHTTPService and TDSHTTPWebDispather components had four specific events, corresponding to the four HTTP methods listed above, and which were designed for mapping the prefix. 在RAD Studio XE中,TDSHTTPService和TDSHTTPWebDispather组件都有四个特定事件,对应于上面列出的四种HTTP方法,并且用于映射前缀。 Those methods do not exist in XE2 and later. XE2及更高版本中不存在这些方法。

While it was possible to map DataSnap POST, PUT, and DELETE HTTP method calls to alternative prefixes in XE, it is not possible to do so in Delphi XE2 through Delphi XE8. 虽然可以将DataSnap POST,PUT和DELETE HTTP方法调用映射到XE中的备用前缀,但是在Delphi XE2到Delphi XE8中不可能这样做。 In those versions you have to stick with Update, Accept, and Cancel, respectively. 在这些版本中,您必须分别坚持使用Update,Accept和Cancel。 And, to be honest, this is not a real problem. 而且,说实话,这不是一个真正的问题。

It is worth noting that you can map your various HTTP method calls using Embarcadero's Enterprise Mobility Services (EMS). 值得注意的是,您可以使用Embarcadero的企业移动服务(EMS)映射各种HTTP方法调用。 I wrote a white paper and recorded a video presentation about EMS for Embarcadero. 我写了一篇白皮书,并录制了关于Embarcadero EMS的视频演示。 To access the white paper and video, use the following URL. 要访问白皮书和视频,请使用以下URL。

http://www.embarcadero.com/rad-in-action/mobilizing-your-business-with-cary-jensen http://www.embarcadero.com/rad-in-action/mobilizing-your-business-with-cary-jensen

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

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