Skip to content

Commit 5c93da6

Browse files
author
Joel Lee
committed
initial commit
0 parents  commit 5c93da6

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

functionz/functionz.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from typing import Dict
2+
import httpx
3+
4+
5+
class FunctionsClient:
6+
def __init__(self, url: str, headers: Dict):
7+
self.url = url
8+
self.headers = headers
9+
10+
async def invoke(self, function_name: str, invoke_options: Dict):
11+
try:
12+
headers = invoke_options.get('headers')
13+
body = invoke_options.get('body')
14+
response = await httpx.post(f"{self.url}/{function_name}", headers=headers)
15+
is_relay_error = response.headers.get('x-relay-header')
16+
if is_relay_error and is_relay_error == 'true':
17+
return {
18+
"data": None,
19+
"error": response.tex
20+
}
21+
# TODO: Convert type accordingly
22+
23+
return {"data": response.data, "error": None}
24+
except Exception as e:
25+
return {
26+
"data": None,
27+
"error": e
28+
}

pyproject.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[tool.poetry]
2+
name = "functionz"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["Joel Lee <joel@joellee.org>"]
6+
license = "MIT"
7+
8+
[tool.poetry.dependencies]
9+
python = "^3.9"
10+
11+
[tool.poetry.dev-dependencies]
12+
13+
[build-system]
14+
requires = ["poetry-core>=1.0.0"]
15+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)