WebApp.HandleURL Docs Warnings

The example code in the docs contains some warnings about empty paths:

' Don't override an empty request, or a session won't start.
If Not Request.Path.IsEmpty Then

  Response.Write "stuff"
  Response.Status = 200

  ' You MUST return True if you want to override the output.
  Return True
End If

Firstly, what does “override” mean in this context? What is being “overridden”? What happens if I return False and don’t “override” whatever it is?

Secondly, my app is session-less, and it seems to work fine when I allow it to handle empty paths (and return True); are there any hidden bad consequences of not using a path in my API?

Returning true from the HandleURL Event tells the Xojo Web framework that you have handled the request and written any content necessary to the WebResponse yourself. Returning true when there’s no path can prevent normal Web Session based app usage (for say something like a REST API).

Telling the framework that you have handled the request is the “overriding” being mentioned. It’s overriding the web framework behavior.

When the path is empty, this will allow the framework to send the user a page to start a Web Session. When the path is a specific location, not handling the request will pass a 404 to the user (from memory, there isn’t any page content, it’s just a HTTP status of 404).

Then you do want to return true for empty paths to prevent Sessions from starting. This will save resources since Sessions aren’t necessary.

It can help with debugging / logging if you use paths for different endpoints / functionalities. The paths for endpoints will show up in the nginx access / error logs. If you need to be intentionally obscure, then inversely you would want to store as much of that function information as you can in the request body.

1 Like