Overview

FastAPI interview question · Easy difficulty

What is FastAPI and why is it used for building APIs?easy

Status
✓
Type
conceptual
Topic
overview
Frequency
common
Tags
FastAPI, Starlette, Pydantic, ASGI, overview
Answer

FastAPI is a modern Python web framework for building APIs, built on Starlette for the web layer and Pydantic for data validation. It uses Python type hints as a single source of truth to drive request/response validation, serialization, and auto-generated interactive docs.

Explanation

You describe your data shapes once as Python classes (or plain type hints on function arguments), and FastAPI derives parsing, validation, serialization, and documentation from that single definition instead of requiring separate schema files. Out of the box it gives request/response validation from type hints, automatic interactive docs (Swagger UI and ReDoc), native async def support, a built-in dependency injection system, and ASGI-based performance comparable to Node or Go frameworks. This is why it has largely replaced Flask for new API-first Python services.

Follow-upWhat does FastAPI use Starlette and Pydantic for?
Follow-upHow does FastAPI generate its interactive docs?
Follow-upWhy is FastAPI often chosen over Flask for new API-first services?