NetTalk Central

Author Topic: Rest webserver - updating only some fields  (Read 6638 times)

jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Rest webserver - updating only some fields
« on: June 12, 2019, 07:30:15 PM »
Using NT 11.13, Clarion 10, all other templates the latest.
I have a (more or less) working rest server. I receive some fields if I do a GET, for example:
         "clientid" : 394,
         "startatdate" : "2019-05-21",
         "startattime" : "14:30:00",
         "kmstravelled" : 0,
AND, there are fields that are not going out, like for example "device".
I need the client app to specify a field; for example, "kmstravelled".
Now, I did a standard PUT NetWebServiceMethod, which updates the data, BUT
My problem is it is emptying the fields not specified, instead of ignoring them. For example, if the user send just
         "kmstravelled" : 25,
Then kmstravelled it's indeed updated to 25, but clientid, startatdate and startattime are put in zero; which I can solve if I send everything, but the REAL PROBLEM is that "device" is cleared as well, even if it is not in the json package!

This is a simplified example, the actual thing is complex (at least 20 fields), but that's what's happening. Fields that are not in the json package are being set to zero or blank, is that expected, or I'm doing something wrong (not there are much to do wrong, they is almost no code there, mostly all templates settings)?

Thanks,

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Rest webserver - updating only some fields
« Reply #1 on: June 13, 2019, 09:09:26 AM »
This brings back some vague memories of having chased something similar once.

As I recall, the behavior you describe is because of the way the QueueToFile:MyFileName routine works.

You'll observe that that assigns values to table fields for all fields NOT excluded on the template.

FOUND IT!
Pasting below stuff from the third party newsgroup:







jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Rest webserver - updating only some fields
« Reply #2 on: June 16, 2019, 08:22:57 PM »
Hi, Jane.

Thank you, yes, that's exactly what's happening. I set to ignored the fields that must not be changed, but the problem remains that the user might want to change just a different few of the whole list each time; I think that fields not specified in the incoming json package should be ignored as well.

Kind regards,
Jorge Lavera

Jane

  • Sr. Member
  • ****
  • Posts: 372
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Rest webserver - updating only some fields
« Reply #3 on: June 18, 2019, 08:56:14 AM »
From a Clarion mindset, Jorge, I would agree with you.  An update "should" only be updating the changed fields.

But from the standpoint of the web, it makes sense.  And the more so in a world of disconnected/synchronized apps... particularly RESTful ones.

The section on wikipedia describing REST includes:
Quote
"
Statelessness
See also: Stateless protocol
The client-server communication is constrained by no client context being stored on the server between requests. Each request from any client contains all the information necessary to service the request, and the session state is held in the client.

"

Even in the world of Clarion/TPS, we'll do a "set blah = blah; access:mytable.tryupdate()"
Which writes the entire record. 
We as a client are not consciously taking responsibility for writing all the unchanged fields of the table but they are all being written from the buffer that we as a client have fetched and "owned" up until the write back to the database. 

Cheers,

Jane

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Rest webserver - updating only some fields
« Reply #4 on: June 18, 2019, 11:25:28 PM »
Hi Jorge,

hmm. I see where you are coming from here, but I'll need to think about it. Basically you are thinking about an interface that is
action: update
guid: whatever
then  "some fields" - and whatever they send is then updated. (others are left unchanged.)

sort of like a SQL update statement, update (kilos=4) where guid = abc;

I'll let you know what I come up with.

cheers
Bruce

jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Rest webserver - updating only some fields
« Reply #5 on: June 20, 2019, 12:42:13 PM »
Hi, Bruce.

Thank you for jump in.
It could be an option, obviously; but it would be very helpful if at least there would be embeds in the routines code to bypass or complement what is done now. Currently there is not a single embed there (At the beggining and the end of routine QueueToFile:(file), for example), so I cannot even skip the routine and write my own or change what's done in any way.

Also, to be able to change the answer of the error queue, close to ! End of "Start of BuildResultFields Routine", there is this code:

  If Loc:ReturnType = return:json
    If Records(p_web.ServiceErrorQueue)
      jsonResults.append(p_web.ServiceErrorQueue,'ServiceErrors')
    Else

I'd put embeds here:

  If Loc:ReturnType = return:json
    If Records(p_web.ServiceErrorQueue)
      #!EMBED
      jsonResults.append(p_web.ServiceErrorQueue,'ServiceErrors')
      #!EMBED
    Else




Thanks,
Jorge Lavera

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11251
    • View Profile
Re: Rest webserver - updating only some fields
« Reply #6 on: June 24, 2019, 12:55:53 AM »
I've added a bunch of new embeds for 11.15


jlavera

  • Newbie
  • *
  • Posts: 47
    • View Profile
    • Email
Re: Rest webserver - updating only some fields
« Reply #7 on: June 28, 2019, 02:19:22 PM »
Thank you!! very much.