v2026.11.3
All Bundles
Bundle

HTTP server framework. WebServer registers route handlers for GET/POST/PUT/DELETE, parses query params and multipart form data, and supports OAuth token exchange. Compile with -lib net_server.

WebServer

HTTP and HTTP web server

Operations

GetActiveConnections # function

Gets the number of connections being served now

function : GetActiveConnections() ~ Int

Return

TypeDescription
Intconnections being served

GetBoundPort # function

Gets the port this server is bound to. A server started on port 0 is bound to a port the system chose; once Serve has it listening this answers that port, so a program that starts the server in a thread can poll here instead of picking a port number.

function : GetBoundPort() ~ Int

Return

TypeDescription
Intbound port, or 0 if no server has been started (or a server on port 0 is not yet listening)

Example

# serve on a port the system chooses, then find out which
thread := System.Concurrency.Thread->New() {
New() { Parent(); }
method : public : Run(arg : System.Base) ~ Nil {
Web.HTTP.Server.WebServer->Serve(MyHandler->New()->GetClass(), 0, false);
}
};
thread->Execute(Nil);
while(Web.HTTP.Server.WebServer->GetBoundPort() = 0) {
System.Concurrency.Thread->Sleep(10);
};
port := Web.HTTP.Server.WebServer->GetBoundPort();

Serve # function

NOT IMPLEMENTED: starting a HTTP server from a configuration file. The call reports this on standard error and returns without serving; it used to load the file and then silently serve nothing. Use Serve(callback, port) or Serve(callback, port, is_debug) for HTTP, or ServeSecure(filename) for HTTPS, which does read a configuration file.

function : Serve(filename:String) ~ Nil

Parameters

NameTypeDescription
filenameStringconfiguration file (ignored)

Serve # function

Starts a HTTP server that listens for requests

function : Serve(callback:Class, port:Int) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpRequestHandler'
portIntserver port

Example

# start an HTTP server on port 8080 using MyHandler
Web.HTTP.Server.WebServer->Serve(MyHandler->New()->GetClass(), 8080, true);

Serve # function

Starts a HTTP server that listens for requests

function : Serve(callback:Class, port:Int, is_debug:Bool) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpRequestHandler'
portIntserver port
is_debugBooltrue for debug output, false otherwise

Serve # function

Starts a HTTP server that listens for requests on one local address instead of every interface, e.g. "127.0.0.1" to take only clients on this machine. The address is read as by TCPSocketServer->New(address, port): a literal ("127.0.0.1", "::1") or a host name, of which the first IPv4 address (else the first IPv6 one) is bound, so "localhost" binds 127.0.0.1; an empty address binds every interface. An address that cannot be bound is reported on standard error and the call returns.

function : Serve(callback:Class, address:String, port:Int) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpRequestHandler'
addressStringlocal address to bind
portIntserver port

Example

# an HTTP server on port 8080 that only this machine can reach
Web.HTTP.Server.WebServer->Serve(MyHandler->New()->GetClass(), "127.0.0.1", 8080);

Serve # function

Starts a HTTP server that listens for requests on one local address instead of every interface; see Serve(callback, address, port).

function : Serve(callback:Class, address:String, port:Int, is_debug:Bool) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpRequestHandler'
addressStringlocal address to bind
portIntserver port
is_debugBooltrue for debug output, false otherwise

ServeSecure # function

Starts a HTTPS server that listens for requests

function : ServeSecure(filename:String) ~ Nil

Parameters

NameTypeDescription
filenameStringconfiguration file (an example)

Example

# start an HTTPS server from a JSON config file
Web.HTTP.Server.WebServer->ServeSecure("config/server_config.json");

ServeSecure # function

Starts a HTTPS server that listens for requests

function : ServeSecure(callback:Class, port:Int, cert:String, cert_key:String, cert_key_passwd:String) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpsRequestHandler'
portIntserver port
certStringSSL certificate
cert_keyStringSSL certificate key
cert_key_passwdStringSSL certificate password

ServeSecure # function

Starts a HTTPS server that listens for requests

function : ServeSecure(callback:Class, port:Int, cert:String, cert_key:String, cert_key_passwd:String, is_debug:Bool) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpsRequestHandler'
portIntserver port
certStringSSL certificate
cert_keyStringSSL certificate key
cert_key_passwdStringSSL certificate password
is_debugBooltrue for debug output, false otherwise

ServeSecure # function

Starts a HTTPS server that listens for requests on one local address instead of every interface, e.g. "127.0.0.1" to take only clients on this machine. The address is read as by TCPSocketServer->New(address, port): a literal ("127.0.0.1", "::1") or a host name, of which the first IPv4 address (else the first IPv6 one) is bound, so "localhost" binds 127.0.0.1; an empty address binds every interface. An address that cannot be bound is reported on standard error and the call returns.

function : ServeSecure(callback:Class, address:String, port:Int, cert:String, cert_key:String, cert_key_passwd:String) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpsRequestHandler'
addressStringlocal address to bind
portIntserver port
certStringSSL certificate
cert_keyStringSSL certificate key
cert_key_passwdStringSSL certificate password

ServeSecure # function

Starts a HTTPS server that listens for requests on one local address instead of every interface; see ServeSecure(callback, address, port, cert, cert_key, cert_key_passwd).

function : ServeSecure(callback:Class, address:String, port:Int, cert:String, cert_key:String, cert_key_passwd:String, is_debug:Bool) ~ Nil

Parameters

NameTypeDescription
callbackClassclass inherited from 'HttpsRequestHandler'
addressStringlocal address to bind
portIntserver port
certStringSSL certificate
cert_keyStringSSL certificate key
cert_key_passwdStringSSL certificate password
is_debugBooltrue for debug output, false otherwise

SetMaxConnections # function

Sets the most connections served at once; a connection beyond it is answered 503 and closed. Call before Serve. Zero, the default, allows 1024.

function : SetMaxConnections(max:Int) ~ Nil

Parameters

NameTypeDescription
maxIntmost simultaneous connections

Stop # function

Stops the server

function : Stop() ~ Nil

Example

# stop a running HTTP or HTTPS server
Web.HTTP.Server.WebServer->Stop();