Designing your API


> What are some good reference architectures?

See:
Using FastAPI to Build Python Web APIs
Full Stack FastAPI and PostgreSQL - Base Project Generator
Up and running with fastapi series

> How do I do e-mail verification, password resets, etc… with fastapi?

See:
Handle Registration in FastAPI and Tortoise ORM
Handling Email Confirmation During Registration in Flask
Flask Rest API -Part:5- Password Reset
E-commerce API with FastAPI | Sending Verification Emails | FastAPI-Mail

> What does a star(*) mean in a method parameter?

It simply allows you to order your arguments so those without default values can be placed ahead of those that can. It also ensures that keyword arguments are used everywhere (which may or may not be desirable when refactoring code). I usually find it unnecessary except in places where I’m using BackgroundTasks or a depency injected argument somewhere, for example:

@app.get("/")
def get_username(*, db: Session = Depends(get_db), user_id: int) -> str:
    return db.query(User).get(user_id).username

See:
What does a star(*) mean in a method parameter?
Order the parameters as you need, tricks


Dockerizing a FastAPI application


> How can I Dockerize my app?

See:
How to Dockerize a Python App with FastAPI
An Extremely Simple Docker, Traefik, and Python FastAPI Example


Dealing with common errors


> I get an Unprocessable Entity (422) error when I post/put to my API

It usually means the body of your request doesn’t mesh with what your API method is expected. Make sure that the object your passing in matches what you’ve specified, including using the Body(...[,embed=True]) types correctly

See:
Body - Multiple Parameters
Python: FastApi (Unprocessable Entity) error

> AttributeError: ‘coroutine’ object has no attribute ‘X’

Usually means you are missing “await” from async method (fastapi/python)

> I’m using Encode Databases against a postgres database, but my RETURNING statements don’t return all the columns I specify

RETURNING statements work okay with fetch_one/fetch_all. If you are using execute, it won’t work
See: Support for RETURNING

> When I deploy using Nginx reverse-proxy, I get mixed content errors like the one below…

Mixed Content: The page at 'https://page.com' was loaded over HTTPS, but requested an insecure 
XMLHttpRequest endpoint 'http://page.com?filter=xxxx'. 
This request has been blocked; the content must be served over HTTPS.

If you add a trailing slash (/) in your API requests it will fix the problem BUT a much easier solution is to the correct proxy headers for Uvicorn. They should look something like this:

upstream api_server {
    server ${API_HOST}:${API_PORT} fail_timeout=0;
  }
...
server {
  ...
  location ~ /api/ {
    proxy_set_header   Host $host;
    proxy_set_header   X-Real-IP $remote_addr;
    proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header   X-Forwarded-Host $server_name;
    proxy_pass http://api_server;
  }

See the following resources:
Failure to load any static files when deploying with HTTPS
fastapi-react nginx.conf
Add option for adding a trailing slash automatically
Ajax Product Filter does not work in https - Fixed