Class HttpEndpoint() Professional
Class function of the HttpEndpoint class.
An object of the class HttpEndpoint serves as a connection point for incoming HTTP or WebSocket connections. The connection point is active after calling the method :start(). :start() automatically creates a new thread for listening on the port associated with the HttpEndPoint. The port number must be passed as a parameter to the method:new().
For HTTP requests with a URL referring to a local file, the HttpEndpoint loads the file from the hard drive and returns it to the connected web client. The following table lists the extensions and the corresponding MIME types of the resources which are supported by default:
Extension | MIME type |
---|---|
.html | text/html |
.htm | text/html |
.gif | image/gif |
.png | image/png |
.jpg | image/jpeg jpg jpe |
.js | application/x-javascript |
.css | text/css |
.woff | font/woff |
.eot | application/vnd.ms-fontobject |
.otf | application/octet-stream |
.ttf | application/octet-stream |
.svg | image/svg+xml |
.json | application/json |
A web request to a resource without an extension must be handled in application code. For this, a user-defined class must be written containing the logic for handling the request. The class must have the same name as the resource which is requested, and it must be derived from a base class which corresponds to the connection type.
If the client tries to establish a websocket connection, an object of a user-defined class is created. This class must be derived from WebSocketHandler. The following URL instantiates an object from the class MyWebSocketHandler:
In case no websocket connection is to be established, an object is instantiated from a class that must be derived from the class WebHandler. The following URL instantiates an object from the class MyWebHandler, and calls the method :echo(). The parameters specified in the URL are forwarded to the handler method:
The following code fragment demonstrates the implementation of the handler that corresponds to the URL above:
In addition to plain text connections, HTTP end points also support servicing requests via the Secure Socket Layer (SSL) protocol. For this, an SSL certificate must first be installed on the computer. Once the end point is bound to this certificate, HTTP and web socket connections to this end point can be established via SSL for increased security.
The following code fragment demonstrates the general procedure:
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.