#1 2019-03-27 16:03:26

tech
Member
Registered: 2014-01-13
Posts: 110

Batch send over URI

Hi,

I am trying to send a batch insert with postman to the sample 04- HTTP Server, but I get "TSQLRestServerDB.EngineBatchSend: Wrong POST" and only 2 inserted records for this example :

URI : localhost:8080/root/samplerecord/batch
{"samplerecord":["POST", { "Time": "135504637423","Name": "Name1","Question": "Question1"},
			  "POST", { "Time": "135504637423","Name": "Name2","Question": "Question2"},
        		  "POST", { "Time": "135504637423","Name": "Name3","Question": "Question3"}
    			]
}

It seems like my json file is not complete.

Regards,

Offline

#2 2019-03-27 17:14:35

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

Re: Batch send over URI

I guess the easiest is to see TSQLRestServer.EngineBatchSend expectations, and use the debugger to see what's wrong.
From the source, "Wrong POST" message indicates a wrong object after the "POST", item...

It sounds pretty unsafe to do so on production anyway...
Anyone with the URI could break your data...

Offline

#3 2019-03-28 11:05:46

tech
Member
Registered: 2014-01-13
Posts: 110

Re: Batch send over URI

I think the problem is at line 28828 of mormot.pas

  P := GotoNextJSONObjectOrArray(Beg);

for the example above, this command returns the next jsonobject for the two first objects, but for the last one it retuns a null pointer what is normal and abort the post process with the exception "Wrong POST".

ab wrote:

It sounds pretty unsafe to do so on production anyway...
Anyone with the URI could break your data...

What is the safe way to invoke a batch from a javascript client to prevent breaking data?

Regards,

Offline

#4 2019-03-28 17:13:44

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

Re: Batch send over URI

So it should work without the spaces/linefeeds between the data?

The safe way is to publish a REST service, which will validate the user rights, sanitize the data if needed, then run the ORM query.

Offline

#5 2019-03-29 10:32:26

tech
Member
Registered: 2014-01-13
Posts: 110

Re: Batch send over URI

Ok great that works without spaces/linefeeds.

I'll test your proposation about REST service.

Thank you AB.

Offline

Board footer

Powered by FluxBB