Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

REST Datasnap override URI mapping

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?

like image 362
MBulli Avatar asked Dec 03 '25 18:12

MBulli


2 Answers

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.

like image 171
Geerten Avatar answered Dec 06 '25 10:12

Geerten


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

like image 25
Anders E. Andersen Avatar answered Dec 06 '25 10:12

Anders E. Andersen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!