Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying URLs on a Rest Server in Delphi

I've written a REST server in Delphi XE (using the wizard) and I want to change the URLs a bit so that instead of having http://192.168.1.84:8080/datasnap/rest/TServerMethods1/GetListings I get something that looks more like http://192.168.1.84:8080/GetListings

Is there a nice easy of doing this?

like image 344
Alister Avatar asked Dec 01 '10 01:12

Alister


2 Answers

The naming convention is (Delphi XE3):

http://my.site.com/datasnap/rest/URIClassName/URIMethodName[/inputParameter]

You can easily change the "datasnap" and "rest" part of the URL in the TDSHTTPWebDispatcher component properties. You can change the Class Name and Method Name of the URL by simply changing the name of your class and method. However, you still have to have 4 components to the URL, so for example it could be:

http://my.site.com/api/v1/People/Listing

See here:

http://docwiki.embarcadero.com/RADStudio/XE3/en/REST#Customizing_the_URL_for_REST_requests

like image 96
Joel Avatar answered Sep 24 '22 02:09

Joel


You could put IIS or Apache in between to accomplish this, and indeed rewrite the URL to point to your service the way you like.

That provides some more advantages anyway (security and scalability mostly). For example, you can create a fail-safe setup with double servers, or you can create multiple machines with your service, and have your web server do the load balancing for example.

You'll get extra logging capabilities, and if you easily want to serve other web content it's easy to have a full fledged web server anyway.

like image 20
Wouter van Nifterick Avatar answered Sep 24 '22 02:09

Wouter van Nifterick