Getting Started with FastAPI [chapter 1]

Fastapi is very easy and everyone can learn. I never read the introduction line so i like to move straight to the api development

» In the tutorial i am using a ubuntu device

Make a very basic fastAPI project

# Create the Root project folder
>> mkdir projectName

# Create the virtual environment for the project
>> cd projectName
>> python3 -m venv envfolderName
>> . envfoldername/bin/activate

# Install FastAPI
>> pip freeze > requirements.txt
>> pip install "fastapi[standard]"

Now that we have make a project folder and installed the fastapi. let’s create the simple api

But Before this, let create the app folder inside root folder

# Making the app folder inside the root folder
>> mkdir app
>> cd app && touch main.py

Let’s revise the previous steps with reference with this image.

First watch at the folder structure.

My root folder is tutorial1 which is cannot be seen in the image. I create the virtual environment folder name “.venv”, and my i created the folder name “app” which will now contain my all api code.

Second let’s write some code in main.py file

The main.py which will serve the basic api. In the above image there is main.py. This is what we need. I will not explain the code as it is very simple to understand. Now the script to run the main.py code.

# Run Our basic api we created in main.py file
>> fastapi dev app/main.py

Now you will get something like this.

as I didn’t have the complete image of cli, but it should be like this. There is already the docs ui ready at url “127.0.0.1:8000/docs” and the our api is ready at “http://127.0.0.1:8000/”

» Now we have complete the basic tutorial of fastapi let’s move to next chapter.