#1 2017-09-28 07:28:39

factor200x
Member
Registered: 2017-05-23
Posts: 15

I need help...

Hello,

in the example "14 - Interface based services" I added a function "Add1":

function Add1(const Data: TRecTest): integer;

Die Parameter N1 und N2 habe ich in einem Record definiert:

type
  TRecTest = packed record
    n1: integer;
    n2 : integer;
  end;

I now want to receive the JSON string sent by the client via the parameter of the funtion.

From Client comes:

http://localhost:8888/root/Calculator.add1/?n1=1&n2=2

In function "Add1":

...

result := Data.n1 + Data.n2;

...

I tried everything but the record "Data" is always "empty". What am I doing wrong?

I would be very, very grateful if someone could help me.


Thank you very much
Olaf

PS:
Please excuse my bad english!

Offline

#2 2017-09-28 08:25:26

Chaa
Member
Registered: 2011-03-26
Posts: 249

Re: I need help...

You can try this:

http://localhost:8888/root/Calculator.add1/?Data={n1:1,n2:2}

Offline

#3 2017-10-02 13:00:31

factor200x
Member
Registered: 2017-05-23
Posts: 15

Re: I need help...

Hello Chaa,

thank you very much! This has already helped me once before.

However, I still have a problem with understanding. I use the "Postman" program to make test calls. If I refer to the API "Add1" and transfer the parameters from "Data={N1:5, N2:13}" as form-data, they will not be forwarded within the server.

Only if I transfer them as "RAW" format, they can be read within the function.

In plain language:

URL

http://localhost:8888/root/Calculator.add1
...
Form-Data

Data: {N1:5, N2:13}

In the server in the function "Add1" the parameter "Data" is empty.

...
RAW

{Data: {"n1": 10,"n2": 2}}}

In the server in the function "Add1" the parameter "Data" is filled.


Since I'm moving quite new in the REST server world, it's a little hard for me to do that. Unfortunately, my search via Google has not been successful so far.

Thank you in advance for any help!!!!

regards
Olaf

Offline

#4 2017-10-02 16:44:29

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,660
Website

Re: I need help...

Form-Data is a HTML feature, not a REST feature, IIRC.
Form-Data is a way of sending information from a HTML form fields.

So it is not supported by REST, which expects true JSON content.

Online

#5 2017-10-03 09:28:56

factor200x
Member
Registered: 2017-05-23
Posts: 15

Re: I need help...

Hello, Ab,

Thank you very much now I have understood it! : -)

Offline

Board footer

Powered by FluxBB