Delphi implements a REST server

I have a mysql database on the server and I insert data into it using the script I wrote. I need to open www.mywebsite.com/rest/create.php?param=value¶m2=value2 to create a new resource, then I need to open another php file to edit the item and so on. This is the main approach: the php file takes some parameters, and then saves the files in the database.

I use TIdHTTP because I have the ability to do something like:

 TIdHTTP1.Get(www.mywebsite.com/rest/create.php?param=value&param2=value2); 

The create.php page returns some data encoded in json. In my Android application, I created a client for relaxation that can parse the json received in response to the php page. For example, if I called .../show.php?id=3 , the result of the page is json with my data; later, the android application will analyze them and show some results to the user.


Question

Instead of calling www.mywebsite.com/rest/create.php?param=value¶m2=value2 I would like to be able to do something like this: www.mywebsite.com/rest/create/?param=value& param2 = value2. Basically, I don't want to use the file name in * .php, but I want to use the second type of URI without the file name.

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

Possible solution . After reading Expert Delphi I found a possible solution. I can create a WebBroker server for linux (so that I can export the Apache * .so module), follow these steps:

enter image description here

When there is a request / rest / create / (using the OnAction event), I can run TIdHTTP1.Get(www.mywebsite.com/rest/create.php?param=value¶m2=value2); and save the result. This way I can open www.mywebsite.com/rest/create/ as I need and save the data. Can a get request be executed even if it is on a Linux machine (as an apache module)? I saw that the standalone server is running under the index, so I think indy should be able to work with the apache module.

Unfortunately, I'm pretty new to these kinds of things, in fact I also don't know what to search on the Internet to find a solution. My solution may work, but I am sure that there is the right effective way for this.

Note : this is just an idea after some research that I have done, and I'm not sure if this is the right way to do what I need. Instead of doing what I wrote above, do I just need to do something with PHP or Apache? Is there any other standard (and better) way to create a REST service?

+5
source share
1 answer

Your problem is not on the side of Delphi, but on the server.

If you need the URL / rest / create /, you just need to create the "create" folder in the "rest" folder on your server and put the index.php file on it.

Or you can use the rules for rewriting URLs in a .htaccess file.

+2
source

Source: https://habr.com/ru/post/1271276/


All Articles