HandleSpecialURL alternative for app level data in Web2.0

Hi team,
I’m busily porting my 1.0 web app across to 2.0 and am having trouble getting my head around HandleURL as opposed to HandleSpecialURL.

In the past, I’ve used another helper app to send data to my web server using a loadURL call to 127.0.0.1:8080/special/folder/file?“mydatahere”
I had an event handler at the app level that read this string and then saved it for use in realtime in my website.

I don’t want this data to be session specific, I just want to fire the event when data is received and save it somewhere much like the old SpecialURL did. Any suggestions on how I should be doing this?

You can use HandleURL with something like

Function HandleURL(Request As WebRequest, Response As WebResponse) Handles HandleURL as Boolean
  If Request.Path = "" Then
    Return False
  End If
  
  If Request.Path.BeginsWith("special") Then
    Var Folder As String = Request.Path.NthField("/", 2)
    Var File As String = Request.Path.NthField("/", 3)
    Var Data As String = Request.QueryString
    // Do something with the variables
    Response.Status = 200
    Return True
  End If
  
  Return False ' Generate a 404 error
End Function

Untested, but you get the idea.

Thanks Wayne,

Worked a treat, for some reason I thought I’d tried this bt it works with this code!

J

So all /api and /special entries come in at WebApplication.HandleURL in the new version?

I’m just double checking as the docs confused me (probably not completely updated)…

https://documentation.xojo.com/api/web/webapplication.html#webapplication-handleurl

You can use this to essentially serve data from just about any URL that you want. There are a few exceptions for things that are reserved and will not call this event:

{snip}

WebApplication.HandleSpecialURL states it was removed in version 2020r1 though.