Skip to content

Commit

Permalink
Add async wrapper (#6)
Browse files Browse the repository at this point in the history
* Add async wrapper
* Update requirements.txt
* Update README.md
  • Loading branch information
tonybaloney authored Oct 26, 2022
1 parent a752452 commit c3a3897
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 10 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ The `requirements.txt` file has an additional dependency of the `fastapi` and `n
```
azure-functions
fastapi
nest_asyncio
```


Expand Down Expand Up @@ -84,11 +83,8 @@ In that same folder, the `__init__.py` file uses `AsgiMiddleware` to redirect in
```python
import logging
import azure.functions as func
import nest_asyncio
from FastAPIApp import app # Main API application

nest_asyncio.apply()


@app.get("/sample")
async def index():
Expand All @@ -105,7 +101,7 @@ async def get_name(name: str):

async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
"""Each request is redirected to the ASGI handler."""
return func.AsgiMiddleware(app).handle(req, context)
return await func.AsgiMiddleware(app).handle_async(req, context)
```

## Running the sample
Expand Down
5 changes: 1 addition & 4 deletions WrapperFunction/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import logging
import azure.functions as func
import nest_asyncio
from FastAPIApp import app # Main API application

nest_asyncio.apply()


@app.get("/sample")
async def index():
Expand All @@ -21,4 +18,4 @@ async def get_name(name: str):


async def main(req: func.HttpRequest, context: func.Context) -> func.HttpResponse:
return func.AsgiMiddleware(app).handle(req, context)
return await func.AsgiMiddleware(app).handle_async(req, context)
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@

azure-functions
fastapi
nest_asyncio

0 comments on commit c3a3897

Please sign in to comment.