Geek Culture

A new tech publication by Start it up (https://medium.com/swlh).

Follow publication

Python : Inter API communication using FastAPI and requests

Tushar Tiwari
Geek Culture
Published in
1 min readFeb 11, 2023

--

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
Sample of coolname API

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.

Sign up to discover human stories that deepen your understanding of the world.

--

--

Tushar Tiwari
Tushar Tiwari

Written by Tushar Tiwari

Finding insights from data | Fascinated by how Markets works.

No responses yet

Write a response