简体   繁体   中英

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?

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

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.

URL 重写通常在 Web 服务器配置中完成,在 Apache 中使用.htaccess 文件中的条目

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM