Zum Hauptinhalt springen
ProdukteDesktop-WerkzeugeTASTECADZeichnungsprüfungTASTEFILESDateiverwaltungTASTEFTPDateiübertragungTASTESSHRemote-ArbeitsbereichTASTEZIPKomprimieren und EntpackenTASTEWINMDateiverwaltungEntwicklerwerkzeugeTASTECODEIntegrierte Entwicklungsumgebung für RustTASTESTUDIOIntegrierte Entwicklungs- und TestumgebungTASTEETLDatenintegration (ETL)ServerTASTEREMOTERemote-Desktop-ServerTASTEGEOGeodatenserverTASTEMAILE-Mail-ArbeitsbereichInvestierenTASTESTOCKDesktop-App für automatischen AktienhandelErste SchritteDownloadsDokumentationKaufenAlle Produkte
Marktplatz
Neuigkeiten
TechnikNeuigkeitenEntwickler-News von heuteEntwicklerdokuProgrammiersprachenRustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDartWeb-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngularServer-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · ExpressApp- & Desktop-FrameworksTauriFlutterReact NativeElectronAlgorithmenAlgorithmus-GrundlagenKernalgorithmenFortgeschrittene AlgorithmenAlgorithmen für die Praxis
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcaseCommunity-Leitfaden
ZusammenarbeitWissenstransferWebsite-AufbauDesktop-App-AufbauRelease- und ZahlungspipelineVertriebspartnerKontakt
DiensteRemote-DesktopIndividuelle Installationspakete
TASTEDEV
Produkte

Desktop-Werkzeuge

TASTECADKomplexe Zeichnungen, mühelos geöffnetTASTEFILESNur die Dateien, die zählen – in BestzeitTASTEFTPDer aufgeräumteste Weg für Ihre DateienTASTESSHDie stärkere Verbindung zu Ihren ServernTASTEZIPSchneller packen, sicherer entpackenTASTEWINMEin tastaturorientierter Dateimanager mit zwei Fenstern

Entwicklerwerkzeuge

TASTECODERust-Apps bearbeiten, bauen, debuggen und testen – alles in einem FensterTASTESTUDIOVom Bearbeiten bis zu Remote-Tests und freigegebenen KI-KorrekturenTASTEETLDaten bewegen, die Werte im Blick

Server

TASTEREMOTEEin Remote-Desktop auf Ihrem eigenen ServerTASTEGEOEin GeoServer-kompatibler Geodatenserver, neu aufgebaut in RustTASTEMAILIhre E-Mail wieder in Ihrer Hand

Investieren

TASTESTOCKAutomatischer Aktienhandel nach Ihren Regeln: wann und was

Erste Schritte

DownloadsNeueste Versionen aller ProdukteDokuSo nutzen Sie jedes ProduktKaufenAbos und DauerlizenzenAlle ProdukteAlle Produkte im Überblick
Alle Produkte
MarktplatzNeuigkeiten
Technik

Neuigkeiten

Entwickler-News von heuteOffizielle Meldungen zu Sprachen, Frameworks, GitHub und KIEntwicklerdokuAnleitungen zu Sprachen, Frameworks und Algorithmen

Programmiersprachen

RustTypeScriptJavaScriptPythonGoC#JavaCC++KotlinDart

Frameworks

Web-Frontend-FrameworksNext.jsReactVue.js · NuxtSvelteKitAngular
Server-FrameworksSpring BootDjangoFastAPIASP.NET CoreNestJS · Express
App- & Desktop-FrameworksTauriFlutterReact NativeElectron

Algorithmen

Algorithmus-GrundlagenKomplexitätsanalyse · Sortieren · Suchen · Grundlegende Datenstrukturen · Bäume und HeapsKernalgorithmenGraphtraversierung · Kürzeste Wege und minimale Spannbäume · Dynamische Programmierung · Greedy-Algorithmen · Teile und herrsche · BacktrackingFortgeschrittene AlgorithmenZeichenkettenalgorithmen · Mathematik und Zahlentheorie · Bitmanipulation · Segmentbäume · Union-FindAlgorithmen für die PraxisStrategie für Coding-Interviews · LRU-Cache · Rate Limiting · Konsistentes Hashing
Alle Entwicklungsdokumente
Community
ProjekteEntwickler und Projekte entdeckenEntwicklungslogsEntscheidungen und ErkenntnissePromptsWiederverwendbare AnweisungenProbleme mit KI-ToolsProbleme und Workarounds für Claude, Codex, GeminiShowcaseFertige ErgebnisseCommunity-LeitfadenWie wir offen entwickeln
Zusammenarbeit
WissenstransferNative Apps mit Rust und eguiWebsite-Aufbau10 Sprachen, Konten, Dokumentation und DownloadsDesktop-App-AufbauRust und egui, ohne WebViewRelease- und ZahlungspipelineSignatur, MSI, deb, rpm, AppImage, PrüfsummenVertriebspartnerEmpfehlen und 30 % erhaltenKontaktEntwicklung, Partnerschaft, Investition
Dienste
Remote-DesktopIhren Computer im Browser erreichenIndividuelle InstallationspaketeNur nötige Funktionen, Einstellungen vorab
Kaufen
DE
한국어EnglishDeutschEspañolFrançaisItalianoPortuguês (Brasil)日本語简体中文繁體中文
Anmelden
Anmelden
TASTEDEV

Von kleinen Werkzeugen zu besserer Entwicklung.

support@tastedev.netTASTEDEV unterstützen
ProdukteProduktübersichtKaufenDokuDownloadsMarktplatzSupport
CommunityProjekteEntwicklungslogsPromptsProbleme mit KI-ToolsShowcase
RichtlinienÜber unsDatenschutzerklärungNutzungsbedingungenAbo-BedingungenRückerstattungCommunity-Richtlinien
KontoAnmeldenRegistrieren
Besucher
Heute
Gestern
Aufrufe gesamt
Firma
GXSOFT
Vertretungsberechtigt
CHOI YOUNG GU
Handelsregisternummer
853-44-00368
Anschrift
9F V24, 351 Gyeongin-ro, Michuhol-gu, Incheon, Republic of Korea
Telefon
+82-10-4404-1523
E-Mail
whitecalvin@tastedev.net
Datenschutzbeauftragter
CHOI YOUNG GU

© 2026 TASTEDEVProduktinformationen basieren auf verifizierten Entwicklungsquellen.Veröffentlicht · wird verbessert

FastAPI-Dokumentation
FastAPI
Getting Started with FastAPIProject StructureCore ConceptsData and StateTestingDeployment
Diskussionen

FastAPI-Anleitung · 3/6

Core Concepts

Dieses Kapitel ist vorerst nur auf Englisch verfügbar.

Almost everything in FastAPI follows from one idea: declare it with type hints and the framework handles the rest. This chapter walks through path operations, path, query and body parameters, Pydantic models and validation, dependency injection, async def versus def, and the OpenAPI docs.

Path operations

FastAPI calls the combination of an HTTP method and a path a path operation. You declare one with @app.get, @app.post, @app.put, @app.patch or @app.delete, and that is also where you set the status code and response model.

from fastapi import FastAPI, HTTPException, status

app = FastAPI()
items: dict[int, str] = {1: "Keyboard"}


@app.delete("/items/{item_id}", status_code=status.HTTP_204_NO_CONTENT)
def delete_item(item_id: int):
    if item_id not in items:
        raise HTTPException(status_code=404, detail="Item not found")
    del items[item_id]

Raising HTTPException stops processing immediately and returns the given status code with a {"detail": ...} JSON body. Routes are matched in the order they are declared, so a fixed path such as /users/me must come before /users/{user_id}.

Path and query parameters

A function parameter whose name matches a {name} in the path is a path parameter; any other parameter with a simple type is a query parameter. Extra validation rules are attached with Annotated plus Path or Query.

from typing import Annotated

from fastapi import FastAPI, Path, Query

app = FastAPI()


@app.get("/users/{user_id}/items")
def list_user_items(
    user_id: Annotated[int, Path(ge=1)],
    q: Annotated[str | None, Query(max_length=50)] = None,
    skip: int = 0,
    limit: Annotated[int, Query(le=100)] = 10,
):
    return {"user_id": user_id, "q": q, "skip": skip, "limit": limit}

A parameter without a default is required; one with a default is optional. Constraints such as ge, le, min_length and pattern drive validation and show up in the OpenAPI docs as well.

Request bodies and Pydantic models

JSON bodies are declared as classes that inherit from Pydantic's BaseModel. When a parameter's type is a Pydantic model, FastAPI reads it from the request body.

from fastapi import FastAPI
from pydantic import BaseModel, Field

app = FastAPI()


class ItemCreate(BaseModel):
    name: str = Field(min_length=1, max_length=100)
    price: float = Field(gt=0)
    tags: list[str] = []


class ItemPublic(BaseModel):
    id: int
    name: str
    price: float


@app.post("/items", response_model=ItemPublic, status_code=201)
def create_item(item: ItemCreate):
    return ItemPublic(id=1, **item.model_dump())
Fragen zu diesem Kapitel?
Vorheriges KapitelProject StructureNächstes KapitelData and State

If the body is not valid JSON or price is negative, the client automatically gets a 422 response. response_model filters the output down to that model's shape, which keeps fields that only belong on input, such as passwords, from leaking into responses. A return annotation (-> ItemPublic) achieves the same thing.

Dependency injection

Depends is FastAPI's dependency injection mechanism. Declare a function (or class) as a dependency and FastAPI calls it for each request and passes the result to your path operation. Dependencies can take path and query parameters of their own and can depend on other dependencies.

from typing import Annotated

from fastapi import Depends, FastAPI

app = FastAPI()


def pagination(skip: int = 0, limit: int = 10):
    return {"skip": skip, "limit": limit}


Pagination = Annotated[dict, Depends(pagination)]


@app.get("/items")
def list_items(page: Pagination):
    return {"page": page}


@app.get("/users")
def list_users(page: Pagination):
    return {"page": page}

An Annotated type alias lets several routes reuse the same dependency with very little code. Dependencies that use yield can run cleanup code after the response, which is why they are the usual way to manage database sessions (chapter 4). Authentication, permission checks and shared parameters are typically implemented as dependencies too.

async def versus def

Path operations can be declared with either async def or plain def, and FastAPI runs them differently:

DeclarationHow it runsUse it when
async defdirectly on the event loopyou call awaitable async libraries (HTTPX, asyncpg and so on)
defin a separate thread poolyou call blocking libraries (classic DB drivers, file processing)

The trap to avoid is calling blocking code, such as time.sleep() or a synchronous database call, inside an async def function: it stalls the entire event loop. When in doubt, plain def is the safer choice.

import httpx
from fastapi import FastAPI

app = FastAPI()


@app.get("/weather")
async def weather():
    async with httpx.AsyncClient() as client:
        response = await client.get("https://example.com/api/weather")
    return response.json()

Polishing the OpenAPI docs

FastAPI collects every declaration above into an OpenAPI schema. Arguments such as summary, description, tags and deprecated make the docs friendlier, and a function's docstring becomes its description. Set the app's title and version with FastAPI(title=..., version=...).

Summary

  • Declare path operations with decorators and return errors with HTTPException.
  • Validate path and query parameters with type hints, Annotated, Path and Query.
  • Define request bodies and response shapes with Pydantic models and filter output with response_model.
  • Factor shared logic into Depends, and keep blocking code in plain def functions.

0 Kommentare

Top-KommentareNeueste zuerst

Anmelden · Melde dich an, um einen Kommentar zu schreiben.