Android Question Re: How call APIs written in PHP for Get, Post, Put, Delete methods

sivakrith

Member
Licensed User
Longtime User
Hello,
In PHP (with slim framework), we have the following methods
$app->POST('/users', \App\Action\UserCreateAction::class);
$app->PUT('/users', \App\Action\UserUpdateAction::class);
$app->DELETE('/users', \App\Action\UserDeleteAction::class);
$app->GET('/user', \App\Action\UserReadAction::class);
$app->GET('/users', \App\Action\UserListAction::class);

For all the above method(s), The data sent to the server with POST. Yes, additional data need to be sent with POST only even for DELETE, GET, PUT also.

Now we need to call those methods from B4A,
What we could find in B4A, is PostString, PutString, Download, Download2, Delete & Delete2

We could successfully add data by calling POST users using PostString.
We could successfully update data by calling PUT users using PutString

For both Download2, Delete2 we could not send additional data though POST http method. As additional data is a must, we need some way where we can send those additional data. Can you suggest a way to call those DELETE and GET methods, by sending all (additional) day through POST method ?

Happiness Always
BKR Sivaprakash

Updated: We need to send data as encrypted string from B4A, so there should be a way to send it that way.
In PostString, there is a parameter to send it as a string , which we could not find with Delete2 and Download2.
Would like to know whether we need to call Download2 for GET Http Method and Delete2 for DELETE http method ?
 
Last edited:

sivakrith

Member
Licensed User
Longtime User
Additional data is a JSON array, which is encrypted. eg.
[
{
"client_ver": "5.0",
"id": "235"
}
]

Data will differ on different condition, but the format remains the same.
The above data will be encrypted before calling the API.
 
Upvote 0

sivakrith

Member
Licensed User
Longtime User
Thanks aeric,

If we use PostString, then how we can differentiate between Insert, Update & Delete ?
Should we change the methods to
$app->POST('/users/insert', \App\Action\UserCreateAction::class);
$app->POST('/users/update', \App\Action\UserUpdateAction::class);
$app->POST('/users/delete', \App\Action\UserDeleteAction::class);
$app->POST('/users/read', \App\Action\UserReadAction::class);
$app->POST('/users/readall', \App\Action\UserReadAllAction::class);
$app->POST('/users/readmultiple', \App\Action\UserReadMultipleAction::class);

Or other solutions available?
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
If you are developing REST API with authorization then consider to use Basic Authentication or Token such as JWT to protect any authorization access.

No "additional" data will be submitted with DELETE or GET methods.
If you don't want to use POST, then you can pass the id inside the URL using template such as:
PHP:
$app->DELETE('/users/{id}', \App\Action\UserDeleteAction::class);
 
Last edited:
Upvote 0

sivakrith

Member
Licensed User
Longtime User
Thanks aeric,
Will implement Basic Authentication soon.

Yes, generally no additional data will be submitted with DELETE or GET methods. And your suggested method is the way to go.
But in this application, we need to pass additional data. That's why this question (thread).

With no way to send additional data, we have to switch to POST method only.
 
Upvote 0
Top