Thanks. This is a really useful suggestion. I’ve accepted it and created a feature to track the work:
Web applications can expose custom HTTP endpoints
I don’t think copying Xojo’s WebApplication.HandleURL verbatim would fit Objo’s architecture. An Objo WebApplication belongs to one logical browser session, whereas an incoming HTTP request may arrive before any browser session exists. Instead, I’m proposing an optional, process-level WebRequestHandler:
Class Api Inherits WebRequestHandler
Event RequestReceived(request As WebRequest) As WebResponse
If request.Method = "GET" And request.Path = "/health" Then
Return WebResponse.Text("ok")
End If
If request.Method = "POST" And request.Path = "/hooks/orders" Then
Var payload As JSONItem = request.Json()
ProcessOrder(payload)
Return WebResponse.Json(CreateAcceptedReply(), 202)
End If
# The application did not handle this route.
Return Nothing
End Event
End Class
The handler could also be declared Async and use Await. WebRequest would provide query parameters, headers, cookies, text, JSON and binary content, while WebResponse would support status codes, headers, cookies, redirects, text, JSON, binary data and empty responses.
Requests would be processed without creating a browser session or loading a page and its controls. Objo’s internal browser, WebSocket and resource routes would remain protected. The design also includes bounded concurrency, timeouts, cancellation, request-size limits and safe overload behaviour.
This would support both mixed browser/API applications and service-only Web projects with no default WebPage.