Pyjo.Server.Base - HTTP/WebSocket server base class

import Pyjo.Server.Base

class MyServer(Pyjo.Server.Base.object):

    def run(self):
        # Get a transaction
        tx = self.build_tx()

        # Emit "request" event
        self.emit('request', tx)

Pyjo.Server.Base is an abstract base class for HTTP/WebSocket servers and server interfaces, like Pyjo.Server.CGI, Pyjo.Server.Daemon and Pyjo.Server.WSGI.

Events

Pyjo.Server.Base inherits all events from Pyjo.EventEmitter and can emit the following new ones.

request

@server.on
def request(server, tx):
    ...

Emitted when a request is ready and needs to be handled.

server.unsubscribe('request')

@server.on
def request(server, tx):
    tx.res.code = 200
    tx.res.headers.content_type = 'text/plain'
    tx.res.body = b'Hello World!'
    tx.resume()

Classes

class Pyjo.Server.Base.Pyjo_Server_Base(**kwargs)

Pyjo.Server.Base inherits all attributes and methods from Pyjo.EventEmitter and implements the following new ones.

app = None
app = server.app
server.app = MyApp.new()

Application this server handles, defaults to a Pyjo.HelloWorld object.

build_app(app)
app = server.build_app('MyApp')

Build application from class.

build_tx()
tx = server.build_tx()

Let application build a transaction.

daemonize()
server->daemonize;

Daemonize server process.

reverse_proxy = None
boolean = server.reverse_proxy
server.reverse_proxy = boolean

This server operates behind a reverse proxy, defaults to the value of the PYJO_REVERSE_PROXY environment variable.

run(*args, **kwargs)
server.run()

Run server. Meant to be overloaded in a subclass.

Pyjo.Server.Base.object

alias of Pyjo_Server_Base