Skip to content

Commit d8bef3a

Browse files
committed
Add async http
1 parent e810ad2 commit d8bef3a

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

v2/function_app.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import azure.functions as func
22
from copy_blobs.copy_blobs import copy_blobs_bp
33
from http_trigger.http_trigger import http_bp
4+
from http_trigger_async.http_trigger_async import http_async_bp
45
from http_trigger_async_exec.http_trigger_async_execution import http_async_exec_bp
56
from simple_blob_trigger.simple_blob_trigger import simple_blob_trigger_bp
67
from simple_blob_trigger_managed_identity.simple_blob_trigger_managed_identity import (
@@ -15,6 +16,7 @@
1516

1617
app.register_functions(copy_blobs_bp)
1718
app.register_functions(http_bp)
19+
app.register_functions(http_async_bp)
1820
app.register_functions(http_async_exec_bp)
1921
app.register_functions(simple_blob_trigger_bp)
2022
app.register_functions(simple_blob_trigger_mi_bp)

v2/http_trigger_async/__init__.py

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import aiohttp
2+
import azure.functions as func
3+
4+
http_async_bp = func.Blueprint()
5+
6+
7+
@http_async_bp.route(route="http_trigger_async", auth_level=func.AuthLevel.ANONYMOUS)
8+
async def http_trigger_async(req: func.HttpRequest) -> func.HttpResponse:
9+
url = req.params.get("url") or req.get_json().get("url")
10+
if not url:
11+
return func.HttpResponse(
12+
"Please pass a valid worldtimeapi url",
13+
status_code=500,
14+
)
15+
async with aiohttp.ClientSession() as s:
16+
async with s.get(url) as response:
17+
data = await response.json()
18+
return func.HttpResponse(f"It is currently {data['datetime']}")

0 commit comments

Comments
 (0)