Repository: jina-ai/jina
File: jina/serve/runtimes/worker/http_fastapi_app.py (Python)

Code before:
                    req.data.docs = DocList[input_doc_list_model]([data])
                if body.header is None:
                    req.header.request_id = req.docs[0].id

            resp = await caller(req)
            status = resp.header.status

            if status.code == jina_pb2.StatusProto.ERROR:
                raise HTTPException(status_code=499, detail=status.description)
            else:
                if not docarray_v2:
                    docs_response = resp.docs.to_dict()
                else:
                    docs_response = resp.docs
                ret = output_model(data=docs_response, parameters=resp.parameters)
                return ret

    def add_streaming_routes(
        endpoint_path,
        input_doc_model=None,
    ):
        from fastapi import Request

        @app.api_route(
            path=f'/{endpoint_path.strip("/")}',
            methods=['GET'],
            summary=f'Streaming Endpoint {endpoint_path}',
            tags=["streaming"],
        )
        async def streaming_get(request: Request, body: input_doc_model = None):
            if not body:
                query_params = dict(request.query_params)
                body = (
                    input_doc_model.parse_obj(query_params)
                    if docarray_v2
                    else Document.from_dict(query_params)
                )
            req = DataRequest()
            req.header.exec_endpoint = endpoint_path
            if not docarray_v2:
                req.data.docs = DocumentArray([body])
            else:
                req.document_array_cls = DocList[input_doc_model]
                req.data.docs = DocList[input_doc_model]([body])
            event_generator = _gen_dict_documents(await caller(req))
            return EventSourceResponse(event_generator)

    for endpoint, input_output_map in request_models_map.items():
        if endpoint != '_jina_dry_run_':
            input_doc_model = input_output_map['input']['model']
            output_doc_model = input_output_map['output']['model']

Review comment (suggestion):
The following code works, but I did not allow get since it doesn't work with gateway deployments.

```python
methods=['GET', 'POST'],
```

Code after:
                    req.data.docs = DocList[input_doc_list_model]([data])
                if body.header is None:
                    req.header.request_id = req.docs[0].id

            resp = await caller(req)
            status = resp.header.status

            if status.code == jina_pb2.StatusProto.ERROR:
                raise HTTPException(status_code=499, detail=status.description)
            else:
                if not docarray_v2:
                    docs_response = resp.docs.to_dict()
                else:
                    docs_response = resp.docs
                ret = output_model(data=docs_response, parameters=resp.parameters)
                return ret

    def add_streaming_routes(
        endpoint_path,
        input_doc_model=None,
    ):
        from fastapi import Request

        @app.api_route(
            path=f'/{endpoint_path.strip("/")}',
            methods=['GET'],
            summary=f'Streaming Endpoint {endpoint_path}',
        )
        async def streaming_get(request: Request = None, body: input_doc_model = None):
            if not body:
                query_params = dict(request.query_params)
                body = (
                    input_doc_model.parse_obj(query_params)
                    if docarray_v2
                    else Document.from_dict(query_params)
                )
            else:
                if not docarray_v2:
                    body = Document.from_pydantic_model(body)
            req = DataRequest()
            req.header.exec_endpoint = endpoint_path
            if not docarray_v2:
                req.data.docs = DocumentArray([body])
            else:
                req.document_array_cls = DocList[input_doc_model]
                req.data.docs = DocList[input_doc_model]([body])
            event_generator = _gen_dict_documents(await caller(req))
            return EventSourceResponse(event_generator)

    for endpoint, input_output_map in request_models_map.items():
        if endpoint != '_jina_dry_run_':