7

I need to write a simple REST-server in Delphi and a client in Ruby on Rails. I've watched all of the videos by Marco Cantu about REST in Delphi and I've got a question:

How can Delphi process requests like "/users/1" where 1 is the ID of a user?

All of the examples I've seen use simple functions (like EchoString(value) or ReverseString(Value)) and the request is "Datasnap/rest/ClassName/EchoString/Value", but I need a request like "Datasnap/rest/classname/123".

For example: TContractsCollection is a collection of contracts and I want to view the contract with ID=324556. So in a browser (and in the RoR client) it will be (for example):

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

But Delphi writes:

"TContractsCollection method not found in the server method list"

Any ideas?

w5m
  • 2,286
  • 3
  • 34
  • 46
yamaxim
  • 171
  • 2
  • 6
  • There is a new lightweight framework for Delphi and Free Pascal which includes [RESTful services support](http://mikejustin.wordpress.com/dwf/) with request parameter mapping so you could declare the URL with placeholders like `/users/{userId}`. (I am the author of this framework) – mjn Jul 02 '12 at 12:13
  • Exposing internal implementation details of the server like the class name (TContractCollection) is not a good RESTFul design. The entities (or resources) should be named in an easy to understand way. A RESTFul URL in this case would be http://mydomain.com/resources/contracts/324556, for more examples see http://stackoverflow.com/a/256359/80901 – mjn Jul 02 '12 at 12:19
  • thanks, mjn. I've wrote it to accent that this is a class. – yamaxim Jul 02 '12 at 12:22
  • Old unanswered question. Anyway, my small comment: Do you want to do that with DataSnap or do you accept to do it using ICS? This is easy to do with ICS, so let me know if you want sample code demonstrating that. – fpiette Nov 03 '13 at 16:06

1 Answers1

0

You can define a function in the TdmServerModule like function

ProcessContract(ContractNo:Integer): String 

when

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

is called, the ContractNo will be set to 324556

Thomas
  • 1
  • 1