在Delphi中使用REST请求

时间:2012-07-02 11:44:55

标签: delphi rest

我需要在Delphi中编写一个简单的REST服务器,在Ruby on Rails中编写一个客户端。我已经观看了Marco Cantu关于Delphi中REST的所有视频,我有一个问题:

Delphi如何处理"/users/1"之类的请求,其中1是用户的ID?

我见过的所有示例都使用简单的函数(如EchoString(value)ReverseString(Value)),请求为"Datasnap/rest/ClassName/EchoString/Value",但我需要"Datasnap/rest/classname/123"之类的请求。

例如:TContractsCollection是合同的集合,我想查看与ID=324556的合同。所以在浏览器中(以及在RoR客户端中)它将是(例如):

"http://localhost:3000/DataSnap/rest/TContractsCollection/324556"

但德尔福写道:

"TContractsCollection method not found in the server method list"

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

您可以在TdmServerModule中定义函数,如函数

ProcessContract(ContractNo:Integer): String 

何时

http://localhost:3000/DataSnap/rest/ProcessContract/324556
调用

,ContractNo将设置为324556