FastApi post request from one api to another inside Kubernetes with Python

9/22/2021

I have 2 Apis created with FastApi in pods, and I need one to connect the other: i have something like this in API A:

@router.post(
"/API-A")

response = requests.post(
    "URL I SHOULD ADD BUT IT IS NOT WORKING"
    headers={
        "content-type": "application/json",
    },
    verify=False,
    data=payload.json
).json()

return response

I have been told that, since API B is deployed in kubernetes, I should be calling the service name instead of the DNS, however, It doesn't seem to work. I tried:

 url= api-service/prices (being prices the endpoint of API B, and api-service the serviceName)

I get this error:

Invalid URL 'api-service/prices': No schema supplied.

Am i doing wrong with this? It is my first time calling APIs inside Kubernetes, so, I don't really know how this should be done.

Thank you very Much.

-- eisklat
fastapi
kubernetes
python
rest

0 Answers