How do I map custom HTTP method prefixes on a Delphi DataSnap REST server
Asked Answered
B

1

6

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. 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. 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. That same post also references Marco Cantù's DataSnap white paper, which supposedly also describes how to do this. That white paper says "You can customize these mappings by handling the four corresponding event handlers of the DSHTTPWebDispatcher component."

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. Those methods do not exist in XE2 and later.

Bitters answered 29/1, 2015 at 19:31 Comment(1)
I am beginning to suspect that what I want to do is not possible in the DataSnap framework without some sort of hack. Not a terrible thing, just interesting that XE supported this approach, and XE2 and later does not.Bitters
B
0

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. In those versions you have to stick with Update, Accept, and Cancel, respectively. 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). I wrote a white paper and recorded a video presentation about EMS for Embarcadero. To access the white paper and video, use the following URL.

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

Bitters answered 19/5, 2015 at 13:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.