Skip to content

asrmarco13/my-first-fastapi-example

Repository files navigation

My First FastApi Example

License: GPL3 Latest commit Open Issues Closed Issues Pull requests Stars Watchers

Summary

  1. Introduction
  2. Prerequisites
  3. Execute project
  4. Interactive api docs
  5. Testing

Introduction

An example project based on FastApi. Minimum Python version is 3.8

Prerequisites

Create a random secret key that will be used to sign the JWT tokens. To generate a secure random secret key use the command:

openssl rand -hex 32

Copy the output to the variable SECRET_KEY in app/core/settings.py

Install PostgreSQL or use the docker image.

Create an instance DB and put the connection infos in .env file.

Install the tool Pipenv.

Go to app folder and run:

pipenv install --dev

Execute project

Go to app folder and run:

python app.py

Open your browser at http://127.0.0.1:8080/hello

You will see the JSON response as:

{"message": "Welcome to my FastApi example"}

Interactive api docs

Now go to http://127.0.0.1:8000/docs.

You will see the automatic interactive API documentation (provided by Swagger UI).

Testing

Go to app/tests folder and run:

pytest