Sidecar Tutorial: Server-side

Python 3.10 Is required to follow the Quick Start Tutorial.

In this part of the Quick Start tutorial, the server-side API will be made. Follow the steps below to complete the server-side tutorial.

Create a directory for your application project:


Inside the project directory create a directory named server and create:

  • requirements.txt


In terminal cd into server directory and run commands:

# Create virtual environment for python project.
python -m venv venv
# Activate virtual environment
source venv/bin/activate 
# install required dependencies
pip install -r requirements.txt

Once these commands have been executed and dependencies have been installed, create and copy in the file as illustrated below:
# FastApi Setup for the Quick Start Tutorial
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

# Initiates the FastApi instance
app = FastAPI()

# Enabling CORS to allow access for the Client-side App.

# Route for our API on index page to send over a simple message.
async def index():
    return {"message": "Welcome to IndustryApps!"}

This is a minimal setup to run a FastApi stateless Restful compliant API, this simply returns a message "Welcome to IndustryApps!" when fetched later on the client-side.

The command uvicorn main:app starts the API in case you'd like to test it, which refers to:

  • main: the file (the Python "module").

  • app: the object created inside of with the line app = FastAPI().

By following the link which pops up on terminal you should see the message displayed on the browser window:

FastApi automatically documents its endpoints. By adding /docs endpoint to your API url, the available endpoints of the API will be visible.

Last updated