NetTalk Central

Author Topic: Problem using Source Procedure Template with NetWebClient to GET API data  (Read 4455 times)

Loren

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
I'm trying to use a Source Procedure Template with NetWebClient to GET API data from a website. In a Window template all is fine but in a source template I must be missing something. NetTalk Twilio example is great but I just can't seen to get the hang of it on a source template. With the code below Log returns empty.


In the Process Code section I have:

    net.init()
    log = ''
    url = 'https://api.bigcommerce.com/stores/' & CLIP(XStore) & '/v2/products/skus?sku=' & CLIP(TSKU)
    loc:Message = CLIP(url)
    net.CustomHeader = 'x-auth-client:' & CLIP(XClient) & '<13,10>' & 'x-auth-token:' & CLIP(XAuth)
    net.contentType = CLIP(XType)
    net.SetAccept(CLIP(XAccept))
    net.HTTPVersion = CLIP(XVersion)
    net.Get(url,'')
    net.pagereceived
    RETURN(Log)

In PageReceived PROCEDURE, VIRTUAL I have:

    log = clip(log) & '<13,10>------<13,10>' & self.ThisPage.GetValue()

and in Send PROCEDURE, VIRTUAL I have:

    log = self.packet.bindata

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Hi Loren,

So the short answer is, you need the Window.

This is because, compared to your CPU, the network is really slow. So you "send something out" and then some time passes, and then you "get something back". If your program just "stopped" during the wait (this is known as a blocking call) the the program's UI is frozen.

So NetTalk is Event based. Meaning that you send "something out" and your procedure keeps running. Then when the reply is returned an Event is sent to your thread - kinda like "hey, got a packet for you". To get an event you need an ACCEPT command, which more-or-less means you need a window. And it's that event (scooped up by a call to net.TakeEvent() that trigger the call to .PageReceived.

So you need a window, BUT if you like you can hide it... just remember to post an Event:Closewindow in both net.PageReceived and net.ErrorTrap.

cheers
Bruce


Loren

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Thanks for the reply, I now understand, I will use the Windows template. So maybe a future new product will be a Capesoft Source template with an Event/Accept loop.<G>

Best Regards
Loren Gregg LaBaw

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Hi Loren,

>> CapeSoft Source template with an Event/Accept loop.

I'm not sure what you are hoping for? A source procedure, with a Window and ACCEPT loop is, um, a Window template (which is in the box.)

I guess I'm not understanding what you are hoping for us to do that a Window Template does not already do.

cheers
Bruce