Emma Rossignoli Emma Rossignoli - 2 months ago 41
reST (reStructuredText) Question

Delphi implement REST server

I have a mysql database on a server and I insert data on it using a script I have written. I have to open

to create a new resource, then I have to open another php file to edit an item an so on. This is the basic approach: a php file takes some parameters and then it stores files on a database.

I am using
because I have the possibility to do something like:


page is returning some data encoded in json. In my android app I have created a rest client that is able to parse the json received in response to the php page. For example, if I called
the result of the page is a json with my data; later the android app will parse them and show some results to the user.


Instead of calling www.mywebsite.com/rest/create.php?param=value&param2=value2 I would like to be able to do something like this www.mywebsite.com/rest/create/?param=value&param2=value2. Basically I dont want to use the filename in *.php but I want to use the 2nd kind of URI without the filename.

The problem is that it's my first time and I don't really know what to do.

Possible solution. After reading
Expert Delphi
I have found a possible solution. I could create a
server for linux (so that I can export the Apache module *.so), implement some actions like this:

enter image description here

When there is a request to /rest/create/ (using the OnAction event) I can run a
and store the result. In this way I can open the www.mywebsite.com/rest/create/ as I need and save the data. Can indy execute a get request even if it is on a linux machine (as apache module)? I have seen that the standalone server runs under indy so I guess that indy should be able to work on an apache module.

Unfortunately I am pretty new with this kind of things, actually I also don't really know what to search online to find a solution. My solution could work but I am pretty sure that there is a proper end efficient way to do this.

Note: this is just an idea after some researches I have made and I am not sure this is the proper way to do what I need. Instead of doing what I've written above, do I simply have to do something with PHP or Apache? Is there another standard (and best) way to create a REST service?

Answer Source

Your problem is not on Delphi side but on server one.

If you want a URL /rest/create/, you simply have to create a folder "create" under "rest" folder on your server and put an index.php file on it.

Or you can use URL rewriting rules in a .htaccess file.