NetTalk Central

Author Topic: Need help understanding NT commands  (Read 1215 times)

PeterPetropoulos

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Need help understanding NT commands
« on: December 22, 2024, 09:30:26 AM »
I have a desktop program communicating with an API server I built.
In the net.PageReceived procedure, I've been advised to use

self.RemoveHeader
self.ServerResponse
self.ThisPage

I don't understand what they do or how to use them.  I am looking for documentation that will tell me how to use these procedures, whether to include parameters or return values, for instance.   Having searched the NT documentation and the Developing pdf, I cannot find them.

Where can I find documentation on these procedures?  Is it a matter of 'read the code?'

Jane

  • Sr. Member
  • ****
  • Posts: 381
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email

PeterPetropoulos

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Need help understanding NT commands
« Reply #2 on: December 26, 2024, 07:59:51 AM »
Jane,

Thank you.  I've read through all this several times.
I need an example that is more than ('something',whatever :-)

I know that there are multiple ways to get this right, but I am losing time getting it wrong.

Having received a token from my REST server after logging in, how do I use that token in formatting the next request?
The generated docs show me how to ask for a record, or a group of records, but I need to get that token in the right place, and that's not happening yet.  I know that because the server is giving me the equivalent of 'I know thee not.'

More specifically, DebugView is showing me that the variable file names are not getting set.  That means my message to the server failed.


Jane

  • Sr. Member
  • ****
  • Posts: 381
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Need help understanding NT commands
« Reply #3 on: December 26, 2024, 11:34:03 AM »
 "C'mon, Man!" TM
Your post asks about ThisPage, RemoveHeader, and ServerResponse but you wanted the reply to be about how to use a token.
 "C'mon, Man!" TM  ;)

In working with  APIs I've found the best strategy FOR ME has been
1. Make it work with Postman
2. Using the Postman stuff as a guide, make it work with the NetDemo app.
3. Having figured that out, code it into my app.

In my apps that need to call an API I typically have two procedures.
1. Fetches a token.  In my case, it first checks to see whether it has an existing token available that hasn't expired.
2. A generic "fetch stuff" API call. 

The "fetch stuff" procedure (sendGetPacket) is a generic window procedure having a prototype of
Code: [Select]
(STRING pURL, STRING pToken,StringTheory pST),LONG
The procedure that wants to fetch something creates the URL for the endpoint creates the required URL and passes the URL, the token, and a String Theory object to the sendGetPacket procedure.  When it's done, the StringTheory parameter contains what I've fetched from the API endpoint and I do what I do with it in the calling procedure.

The sentGetPacket has this code, much of which is snipped out of the NetDemo web client procedure.

Code: [Select]
PacketSend            ROUTINE
DATA

  CODE   

  ThisWebClient.SetAllHeadersDefault()

  ThisWebClient.HeaderOnly = 0
  ThisWebClient.Cookie = ''
  ThisWebClient.CustomHeader = 'Authorization: Bearer '&clip(pToken)
  ThisWebClient.Referer = ''   
  ThisWebClient.AsyncOpenTimeOut = 2200       ! 22 seconds
  ThisWebClient.InActiveTimeout = GLO:QueryTimeout            ! 6000        ! 20 seconds     
  ThisWebClient.SSLMethod = NET:SSLMethodTLS
  ThisWebClient.HTTPVersion = 'HTTP/1.1'
  ThisWebClient.ContentType = 'application/x-www-form-urlencoded'
  ThisWebClient.ConnectionKeepAlive = FALSE
  ThisWebClient.CanUseProxy = GLO:CanUseProxy
  ThisWebClient.ProxyServer = GLO:proxyServer
  ThisWebClient.ProxyPort = GLO:proxyPort 
  ThisWebClient.Fetch(clip(pURL))

The EVENT:OpenWindow event has this embed
Code: [Select]
      ! End of "Window Event Handling"
    OF EVENT:OpenWindow
      ! [Priority 5000]
      DO PacketSend

Other embeds:

Code: [Select]
ThisWebClient.ErrorTrap PROCEDURE(string errorStr,string functionName)

! Start of "NetTalk Method Data Section"
! [Priority 5000]

! End of "NetTalk Method Data Section"

  CODE
  ! Start of "NetTalk Method Executable Code Section"
  ! [Priority 2500]
        if self.Error <> 0
            ud.debug('error trap before parent '&clip(errorstr)&'  '&clip(functionName)&'  code='&ThisWebClient.Error)
            AddLog('net client error '&clip(errorstr),0,0)
            AddErrorLog('net client error '&clip(errorstr)&'  url='&left(pURL,80))
            post(event:closewindow)
        end ! if
  ! Parent Call
  PARENT.ErrorTrap(errorStr,functionName)
  ! [Priority 7500]
 

Code: [Select]
ThisWebClient.PageReceived PROCEDURE

! Start of "NetTalk Method Data Section"
! [Priority 5000]

! End of "NetTalk Method Data Section"

  CODE
  ! Start of "NetTalk Method Executable Code Section"
  ! [Priority 2500]
 
  ! Parent Call
  PARENT.PageReceived
  ! [Priority 7500]
    IF self.ServerResponse = 200
      self.RemoveHeader()
      LOC:RV = TRUE
      pST.SetValue(self.ThisPage.GetValue())
    ELSE
      LOC:RV = FALSE
    END !IF
    post(event:closewindow)
       

This is all OLD CODE I wrote 6 1/2 years ago, but it's been working fine since then.  YMMV.  Much of it, as mentioned, appropriated from the handy dandy NetDemo example program.  UD is the ClarionLive UltimateDebug object.

[edited] because I couldn't stand looking at the ugly pageReceived code I posted so I tweaked that app I pulled this from. [/edited]


HINT - that NetDemo example is handy  ;)

« Last Edit: December 26, 2024, 02:27:39 PM by Jane »

PeterPetropoulos

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • Email
Re: Need help understanding NT commands
« Reply #4 on: December 27, 2024, 09:32:17 AM »
WOO HOO!

IT WOIX!

No errors (reported ;-!  We got Data!

Jane,
Many thanks!

Yoiks and away!

Jane

  • Sr. Member
  • ****
  • Posts: 381
  • Expert on nothing with opinions on everything.
    • View Profile
    • Email
Re: Need help understanding NT commands
« Reply #5 on: December 27, 2024, 02:24:38 PM »