ServerResponder

Package: Libraries.Web · Inherits from: Libraries.Network.NetworkExchangeListener, Libraries.Language.Object

ServerResponder is anything on a website that lives at a location and can answer a request for it. A WebPage is one: by default it answers with its HTML. Other responders answer with data, such as the result of signing in. A WebSite holds its responders by location and gives each request to the one at the request's location. To answer requests, a responder fills in ResponseReceived, from NetworkExchangeListener.

Example Code

use Libraries.Web.ServerResponder
use Libraries.Network.NetworkExchange

class Greeting is ServerResponder
    on create
        SetLocation("greeting")
    end

    action ResponseReceived(NetworkExchange exchange)
        text response = "Hello"
        exchange:SendResponseHeaders(200, response)
        exchange:SendResponse(response)
    end
end

Actions

GetLocation()

Returns where this lives on its website. A class may instead override this action and return its location directly.

Returns

text: The location on the site.

SetLocation(text location)

Sets where this lives on its website, relative to the site's folder and never with a leading slash, such as "tutorials/Scenes/intro.html". A WebSite finds, writes and serves it by this location.

Parameters

  • location text: Where this lives on the site.

Example

use Libraries.Web.Page.WebPage

WebPage page
page:SetLocation("tutorials/start.html")

Inherited Actions

3 actions from Libraries.Language.Object
1 action from Libraries.Network.NetworkExchangeListener