Skip to content

Commit

Permalink
added async httpx library for request processing
Browse files Browse the repository at this point in the history
add sample request processing for app call messages
  • Loading branch information
rasswanth-s committed Feb 25, 2024
1 parent 871db0f commit 67721e8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion notebooks/Testing/Veilid/Alice-Python-Server.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@
"source": [
"res = requests.get(\n",
" f\"http://{host}:{port}/proxy\",\n",
" json={\"url\": \"https://www.google.com\", \"dht_key\": self_dht_key},\n",
" json={\"url\": \"https://www.google.com\", \"method\": \"GET\", \"dht_key\": self_dht_key},\n",
")"
]
},
Expand Down
1 change: 1 addition & 0 deletions packages/grid/veilid/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
fastapi==0.103.2
httpx==0.27.0
loguru==0.7.2
uvicorn[standard]==0.24.0.post1
15 changes: 14 additions & 1 deletion packages/grid/veilid/server/veilid_core.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# stdlib
import json
from typing import Callable
from typing import Optional
from typing import Tuple
from typing import Union

# third party
import httpx
from loguru import logger
import veilid
from veilid import KeyPair
Expand Down Expand Up @@ -33,8 +35,19 @@ async def main_callback(update: VeilidUpdate) -> None:

elif update.kind == veilid.VeilidUpdateKind.APP_CALL:
logger.info(f"Received App Call: {update.detail.message}")
message: dict = json.loads(update.detail.message)

async with httpx.AsyncClient() as client:
response = await client.request(
method=message.get("method"),
url=message.get("url"),
data=message.get("data", None),
params=message.get("params", None),
json=message.get("json", None),
)

async with await get_veilid_conn() as conn:
await conn.app_call_reply(update.detail.call_id, b"Reply from App Call")
await conn.app_call_reply(update.detail.call_id, response.content)


async def noop_callback(update: VeilidUpdate) -> None:
Expand Down

0 comments on commit 67721e8

Please sign in to comment.