pyGrowler / Growler

A micro web-framework using asyncio coroutines and chained middleware.
http://www.growler.rocks
Apache License 2.0
686 stars 29 forks source link

Are views a coroutines? #15

Closed JerzySpendel closed 7 years ago

JerzySpendel commented 7 years ago

Let's take a look at the documentation example:


from growler import App

app = App()

@app.use
def log_file(req, res):
    print("<{ip}> {req_path}".format(ip=req.ip, req_path=req.path))

@app.get("/")
def index_file(req, res):
    res.send_text("index.")

app.create_server_and_run_forever(host='0.0.0.0', port='8080')

Is index_file a coroutine from which I could do a yield from?

akubera commented 7 years ago

Growler accepts both normal functions and coroutine functions as middleware, and will handle each appropriately.

Just adorn the function with @asyncio.coroutine and you can yield from all you like.

Example 2 demonstrates this.

Note, I'm going to drop py3.4 support with my next version (v0.9.x), and I recommend using async & await notation instead of asyncio.coroutine

JerzySpendel commented 7 years ago

Ok, super! :) I didn't find this example in documentation.