Waarom FastAPI?

Introductie tot FastAPI

Matt Eckerle

Software and Data Engineering Leader

Wat is FastAPI?

Eerst wat terminologie

  1. API: Application Programming Interface - webapps die via HTTP gestructureerde data versturen
  2. Webapplicatie: app die verkeer via het web afhandelt
  3. Webframework: framework om webapps te bouwen

FastAPI is een snelle manier om high-performance API's in Python te bouwen

Introductie tot FastAPI

FastAPI: kernfeatures

  • Snel: Zeer hoge performance
  • "Low code" en makkelijk te leren: Python-annotaties en type hints
  • Robuust: Productieklaar met autodoc
  • Standaardgebaseerd: Gebaseerd op OpenAPI en JSON Schema

FastAPI-logo

OpenAPI-logo

JSON-logo

1 https://fastapi.tiangolo.com/
Introductie tot FastAPI

FastAPI vs. andere Python-webframeworks

Flask

  • Bouw webapps (GUI)
  • ORM optioneel

FastAPI

  • Bouw API's
  • ORM optioneel

Django

  • Bouw webapps (GUI)
  • ORM ingebouwd

Belangrijkste verschillen

  • Voor API's zonder databasebewerkingen
  • Data- en machinelearning-transacties
Introductie tot FastAPI

Onze eerste webapp bouwen met FastAPI

1. Installeer FastAPI

pip install fastapi

2. Maak je app in main.py

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Hello World"}

3. Start de server

fastapi dev main.py

REPL waarop FastAPI draait

Introductie tot FastAPI

Voordat we met FastAPI oefenen

Enkele notities

  1. Je kunt de FastAPI-server niet starten met de knop "Run this code"
  2. Zet servercode in de Python-editor als main.py

  3. Run het in de terminal met fastapi dev main.py

  4. Check in de terminal of je ziet: Application startup complete.
  5. Stop de live server met Control + C in dezelfde terminal
  6. Installeer FastAPI ook in je eigen Python-omgeving om daar te oefenen
Introductie tot FastAPI

Laten we oefenen!

Introductie tot FastAPI

Preparing Video For Download...