3

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?

RRUZ
  • 134,889
  • 20
  • 356
  • 483
MBulli
  • 1,659
  • 2
  • 24
  • 36
  • See here for a workaround : http://codeverge.com/embarcadero.datasnap/-xe3-can-you-get-more-control-over-the-m/1097157 – aleroot Jan 30 '15 at 20:10

2 Answers2

2

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.

Geerten
  • 1,027
  • 1
  • 9
  • 22
  • Thanks for your answer I will try it when I'm back in the office. But last time I didn't find these events, I'll take a close look now. – MBulli Dec 24 '11 at 11:08
  • It seems that the above named events are implemented in TDSHTTPServerTransport and TDSHTTPService inherit from it. I searched the source code of TDSHTTPServerTransport but can't find these events. – MBulli Dec 28 '11 at 11:36
  • You do have a TDSHTTPService component on your server design? Because there is where I assigned them. – Geerten Dec 28 '11 at 13:19
  • Yes I added one. I'm using XE2 which version are you running? – MBulli Dec 29 '11 at 08:22
  • I'm using XE, and I'm switching jobs, so I don't use Delphi anymore, and therefore can't look for you in XE2.. – Geerten Dec 29 '11 at 11:01
1

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

Anders E. Andersen
  • 1,635
  • 2
  • 14
  • 20