REST Datasnap 覆盖 URI 映射
我用 delphi XE2 中的 REST datasnap 编写了一个小型 REST 服务器。 HTTP 方法(POST、PUT 等)和 delphi 中定义的函数之间有一个默认映射,这是由 delphi 组件完成的。
此 wiki 条目 描述了 URI 映射,但还指出可以覆盖默认映射由程序员。
映射模式可以被覆盖。用户可以根据类名和方法名参数覆盖每种类型的映射。
但我没有找到任何解释如何覆盖映射。
如何更改默认映射?
I wrote a small REST server with the REST datasnap in delphi XE2.
There is a default mapping between HTTP methods (POST, PUT etc.) and the functions defined in delphi, this is done by a delphi component.
This wiki entry describes the URI mapping but also notes that the default mapping can be override by the programmer.
The mapping pattern can be overridden. The user can override the mapping for each type based on class name and method name parameters.
But I didn't find any explanation how to override the mapping.
How can I change the default mapping?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
TDSHTTPService 组件具有您可以在其中指定每种类型的映射的事件。这些事件称为 RESTMethodNameMapDELETE、RESTMethodNameMapGET、RESTMethodNameMapPOST 和 RESTMethodNameMapPUT。
Marco Cantù 的REST 白皮书中也对此进行了解释,其中解释了很多有关 REST 和 Datasnap 的内容。
The TDSHTTPService component has events where you can specify the mapping for each type. These events are called RESTMethodNameMapDELETE, RESTMethodNameMapGET, RESTMethodNameMapPOST and RESTMethodNameMapPUT.
This is also explained in the white paper on REST by Marco Cantù, which explains a lot about REST and Datasnap.
我也想知道同样的事情,并做了一些实验。看来至少部分可以控制 url。具体来说,我尝试更改 url 的类名部分。
本质上,如果您使用 TComponent 后代,您可以为该类命名任何名称。但是,如果您从 TDataModule 下降,则这不起作用。在这种情况下,您可以创建一个别名类,您可以将其命名为您想要的名称,该名称源自您的 TDataModule。
当尝试绑定到此时,您需要在客户端绑定中进行一些清理,但它似乎有效,至少对于简单的测试而言。
在 Embarcadero 论坛上查看更多信息。
https://forums.embarcadero.com/thread.jspa?threadID=77624& ;tstart=0
I was wondering the same thing, and did some experiments. It seems to be at least partially possible to control the url. Specifically I tried changing the class name part of the url.
Essentially if you are using a TComponent decendant you can name the class anything. This doesn't work if you decend from TDataModule though. In this case you can create and alias class which you can name what you want which decends from your TDataModule.
You need to do some cleanup in the client binding when trying to bind to this, but it seems to work, at least for simple tests.
See more on the Embarcadero forums.
https://forums.embarcadero.com/thread.jspa?threadID=77624&tstart=0