REST Datasnap override URI mapping
Asked Answered
O

2

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?

Oldworld answered 22/11, 2011 at 16:11 Comment(1)
See here for a workaround : codeverge.com/embarcadero.datasnap/…Smoothshaven
G
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.

Grishilde answered 21/12, 2011 at 15:1 Comment(5)
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.Oldworld
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.Oldworld
You do have a TDSHTTPService component on your server design? Because there is where I assigned them.Grishilde
Yes I added one. I'm using XE2 which version are you running?Oldworld
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..Grishilde
A
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

Automate answered 3/10, 2012 at 12:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.