Skip to content

Commit

Permalink
fix: fix get and post endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
NarekA committed Oct 25, 2023
1 parent a72a797 commit ee77d13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion jina/clients/base/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ async def send_streaming_message(self, doc: 'Document', on: str):
'json': doc.dict() if docarray_v2 else doc.to_dict(),
}

async with self.session.post(**request_kwargs) as response:
async with self.session.get(**request_kwargs) as response:

Check warning on line 206 in jina/clients/base/helper.py

View check run for this annotation

Codecov / codecov/patch

jina/clients/base/helper.py#L206

Added line #L206 was not covered by tests
async for chunk in response.content.iter_any():
events = chunk.split(b'event: ')[1:]
for event in events:
Expand Down
14 changes: 4 additions & 10 deletions jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ def add_post_route(
):
app_kwargs = dict(
path=f'/{endpoint_path.strip("/")}',
methods=['GET'],
methods=['POST'],
summary=f'Endpoint {endpoint_path}',
response_model=output_model,
)
Expand Down Expand Up @@ -249,7 +249,7 @@ def add_streaming_routes(

@app.api_route(
path=f'/{endpoint_path.strip("/")}',
methods=['POST'],
methods=['GET', 'POST'],
summary=f'Streaming Endpoint {endpoint_path}',
tags=["streaming"],
)
Expand All @@ -264,13 +264,8 @@ async def event_generator():
):
if error:
raise HTTPException(status_code=499, detail=str(error))
yield {
'event': 'update',
'data': doc.dict()
}
yield {
'event': 'end'
}
yield {'event': 'update', 'data': doc.dict()}
yield {'event': 'end'}

Check warning on line 268 in jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py

View check run for this annotation

Codecov / codecov/patch

jina/serve/runtimes/gateway/http_fastapi_app_docarrayv2.py#L267-L268

Added lines #L267 - L268 were not covered by tests

return EventSourceResponse(event_generator())

Expand All @@ -280,7 +275,6 @@ async def event_generator():
summary=f'Streaming Endpoint {endpoint_path}',
)
async def streaming_post(body: dict):

async def event_generator():
async for doc, error in streamer.stream_doc(
doc=input_doc_model.parse_obj(body), exec_endpoint=endpoint_path
Expand Down
2 changes: 1 addition & 1 deletion jina/serve/runtimes/worker/http_fastapi_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def add_streaming_routes(

@app.api_route(
path=f'/{endpoint_path.strip("/")}',
methods=['GET'],
methods=['GET', 'POST'],
summary=f'Streaming Endpoint {endpoint_path}',
tags=["streaming"],
)
Expand Down

0 comments on commit ee77d13

Please sign in to comment.