B4J Question b4j server - how to send a value to server and get a result back

moster67

Expert
Licensed User
Longtime User
There are som many examples about b4j web-servers and I have difficulties in finding the correct sample.

If I create a Handle, for instance "/gen", how can I pass on to the server a value such 1+2 and make it send back to my app the answer i.e. 3

for instance, I send the following request: http://localhost:17178/gen?1+2
(not sure how I would create the string)
and back I would receive the answer i.e. 3 which I could parse from the response.

Basically I want the server to do an "operation" for me and then send back the result.

Many thanks.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are two parts to your question. How to send a parameter to the server and how to evaluate the parameter.

The url for GET parameters should be:
/gen?expression=1%2B2
%2b = url encoded +
You can then use req.GetParmater("expression") to get the expression.

Evaluate it with B4X Eval.

Return the result with resp.Write.
 
Upvote 0

moster67

Expert
Licensed User
Longtime User
Thanks! Works just the way I wanted. I guess this can also be used for creating APIs for clients.
 
Upvote 0
Top