Python : Inter API communication using FastAPI and requests
Situation:
There is an external / internal API which is required to be used from another new API you are currently writing. And you don’t want to leave comfort of python.
So here we go with an example.
Let’s say we have a existing API like below.
Which takes first_name and last_name and compliments for a cool name.
Save the above file as main_second.py . Run using the below command.
uvicorn main_second:app --reload --host 0.0.0.0 --port 8001

For the calling the existing above API we will use requests library.
This new API has dependency on the above on. So make sure that its up and running.
/goodname API adds another compliment on personality.
Run using
uvicorn main_first:app --reload --host 0.0.0.0 --port 8000

Its done. We are able to call and use external API form another API.
This may not be ideal way of doing it. But it does get the job done.