ZeroIntensity / view.py

The Batteries-Detachable Web Framework
https://view.zintensity.dev
MIT License
205 stars 15 forks source link

Controller Based Routing #194

Open ZeroIntensity opened 2 months ago

ZeroIntensity commented 2 months ago

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()