view.py icon indicating copy to clipboard operation
view.py copied to clipboard

Controller Based Routing

Open ZeroIntensity opened this issue 1 year ago • 0 comments

Proposal:

To fit with other frameworks, view.py should implement controllers (i.e. routing based on classes). This should be pretty easy, actually. This won't be a new loader strategy, but will act sort of like a router. For example:

from view import new_app, get

app = new_app()

class MyController(Controller):
    @get("/")
    def get(self):
        return "Hello, world!"

# Alternatively, we can implicitly call the router function
class MyOtherController(Controller):
    def get(self, test: str):  # Automatic input
        return "Hello, world!"

app.load(MyController(), MyOtherController())
app.run()

ZeroIntensity avatar Jul 08 '24 18:07 ZeroIntensity