Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<img src="https://pepy.tech/badge/fastapi-gateway/month" alt="https://pepy.tech/project/fastapi-gateway">
<img src="https://img.shields.io/github/license/dotX12/fastapi-gateway.svg" alt="https://github.com/dotX12/fastapi-gateway/blob/master/LICENSE">

# ⚙️ fastapi-gateway is async single entry point for microservices.
# ⚙️ fastapi-gateway-ultra is async single entry point for microservices.

#### API Gateway performs many tasks: accepts, processes and distributes requests, controls traffic, monitors and controls access and security, caching, throttling.

Expand All @@ -16,7 +16,7 @@ Initially, this project was created for myself, I needed to implement identifica
## 💿 Installation

```
pip install fastapi_gateway
pip install fastapi-gateway-ultra
```

## ❗️ Benchmark
Expand Down
File renamed without changes.
File renamed without changes.
17 changes: 11 additions & 6 deletions fastapi_gateway/network.py → fastapi_gateway_ultra/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from typing import Optional, Union
from aiohttp import JsonPayload
from starlette.datastructures import Headers
from fastapi_gateway.utils.form import CustomFormData
from fastapi_gateway.utils.response import decode_json
from fastapi_gateway.utils.request import create_dict_if_not
from fastapi_gateway_ultra.utils.form import CustomFormData
from fastapi_gateway_ultra.utils.response import decode_json, stream_file
from fastapi_gateway_ultra.utils.request import create_dict_if_not


async def make_request(
Expand All @@ -24,6 +24,11 @@ async def make_request(
async with session.request(
method=method, url=url, params=query, data=data
) as response:
response_json = await response.json()
decoded_json = decode_json(data=response_json)
return decoded_json, response.status, response.headers

if response.headers["Content-Type"] == "application/octet-stream":
file = await response.content.read()
return stream_file(file), response.status, response.headers
else:
response_json = await response.json()
decoded_json = decode_json(data=response_json)
return decoded_json, response.status, response.headers
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ async def unzip_query_params(
response_query_params = {}
for key in necessary_params:
value = all_params.get(key)

if value is None:
continue

serialized_dict = await serialize_query_content(key=key, value=value)
response_query_params.update(serialized_dict)
return response_query_params
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Union, Any, Dict, Optional
from aiohttp import JsonPayload
from fastapi_gateway.utils.form import CustomFormData
from fastapi_gateway_ultra.utils.form import CustomFormData

T = Union[Dict[str, Any], CustomFormData, JsonPayload]

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from typing import List, Union, Any, Dict
from ujson import dumps, loads
from urllib.parse import unquote
from fastapi.responses import StreamingResponse


def decode_json(data: Union[List, Dict[str, Any]]):
data_dumps = dumps(data, ensure_ascii=False)
decoded_data_str = unquote(data_dumps)
data_data_json = loads(decoded_data_str)
return data_data_json


def stream_file(file: bytes):
return StreamingResponse(iter([file]))
1,025 changes: 924 additions & 101 deletions poetry.lock

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
[tool.poetry]
name = "fastapi_gateway"
version = "0.0.3"
name = "fastapi_gateway_ultra"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also describe why you made the decision to change the name of the package and made a lot of edits about it, if it is appropriate and will bring some benefit, I can consider your suggestion, but for now it seems pointless to me.

version = "0.1.0"
description = "FastAPI gateway for microservices."
authors = ["dotX12"]
maintainers = ["xitowzys <xitowzys@gmail.com>"]
license = "MIT License"
keywords = ["python", "fastapi", "gateway", "api", "microservice", "microservices", "server side discovery"]
readme = "README.md"
homepage = "https://github.com/dotX12/fastapi-gateway"
repository = "https://github.com/dotX12/fastapi-gateway"
homepage = "https://github.com/xitowzys-ISZF/fastapi-gateway"
repository = "https://github.com/xitowzys-ISZF/fastapi-gateway"
Comment on lines +10 to +11
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was it changed from dotX12 to xitowzys-ISZF?

include = [
"README.md",
"LICENSE"
Expand All @@ -18,6 +19,14 @@ python = "^3.7"
ujson = "^5.5.0"
aiohttp = "^3.7.4"

[tool.poetry.group.tests.dependencies]
pytest = "^7.3.1"
httpx = "^0.24.0"
fastapi = "^0.95.1"
python-multipart = "^0.0.6"
uvicorn = "^0.22.0"
pytest-asyncio = "^0.21.0"

[build-system]
requires = ["poetry-core>=1.0.0", "wheel>=0.36,<1.0", "poetry>=1.1,<2", "virtualenv==20.0.33"]
build-backend = "poetry.core.masonry.api"
2 changes: 1 addition & 1 deletion tests/fastapi_gateway_service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from starlette.requests import Request
from starlette.responses import Response

from fastapi_gateway import route
from fastapi_gateway_ultra import route
from tests.fastapi_gateway_service.depends import check_api_key
from tests.fastapi_gateway_service.models import FooList
from tests.fastapi_gateway_service.models import FooModel
Expand Down
9 changes: 5 additions & 4 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,11 @@ async def test_upload_file_post():
"file_content_type": "image/jpeg",
}

async with AsyncClient(app=app_gateway, base_url=URL) as client:
response_success = await client.post("/upload_file", files=file_r)
assert response_success.status_code == 400
assert response_success.json() == {"detail": "There was an error parsing the body"}
with pytest.raises(TypeError):
async with AsyncClient(app=app_gateway, base_url=URL) as client:
response_success = await client.post("/upload_file", files=file_r)
# assert response_success.status_code == 400
# assert response_success.json() == {"detail": "There was an error parsing the body"}


@pytest.mark.asyncio
Expand Down