Fast API crash course

Fast API crash course

Welcome to the crash course on Fast API

Fast API is a comparatively new framework but it is impressing me a lot. I found it so much simpler than the Django REST framework. The built-in docs system is just so cool that I am very sure, it's going to save so much of my time

Fast API is going to bring new standards about what to expect from an API framework

Here is the video for the indepth guide with code walk through:

PipFile generated in this video

name = "pypi"
url = ""
verify_ssl = true


fastapi = "*"
uvicorn = "*"

python_version = "3.8"

Final code file for this Fast API crash course

from fastapi import FastAPI
from pydantic import BaseModel
from typing import Optional

app = FastAPI()

# temp database
fakedb = []

# course model to store courses
class Course(BaseModel):
    id: int
    name: str
    price: float
    is_early_bird: Optional[bool] = None

# Home/welcome route
def read_root():
    return {"greetings": "Welcome to"}

# Get all courses
def get_courses():
    return fakedb

# get single course
def get_a_course(course_id: int):
    course = course_id - 1
    return fakedb[course]

# add a new course"/courses")
def add_course(course: Course):
    return fakedb[-1]

# delete a course
def delete_course(course_id: int):
    return {"task": "deletion successful"}

Make sure to keep an eye on our blog and youtube channel. We are putting a lot of content to serve the programming community

Did you find this article valuable?

Support Learn Code Online by becoming a sponsor. Any amount is appreciated!