Skip to content
tezvyn:

API Design

48 bites tagged API Design — interview questions with model answers, and 60-second explainers.

Python & FastAPI2 min read

How do you mark a FastAPI endpoint as deprecated?

This tests decorator-level OpenAPI configuration in FastAPI. Pass deprecated=True to the path operation decorator, e.g. @app.get("/old", deprecated=True), so Swagger UI shows a strikethrough. Red flag: burying a deprecation warning in the docstring instead.

Python & FastAPI2 min read

Explain SQLAlchemy ORM vs Pydantic models in FastAPI

This tests separation of database schema from API contracts. A strong answer distinguishes SQLAlchemy table rows from Pydantic validation and OpenAPI generation, and notes that create schemas exclude auto-generated IDs.

Python & FastAPI2 min read

How would you implement a dependency requiring multi-source parameters?

Tests if you know FastAPI resolves dependency params like endpoint params. Great answers annotate each parameter with its source inside the dependency so FastAPI injects them independently. Red flag: manually parsing Request or merging values in the endpoint.

Python & FastAPI2 min read

Implement a custom exception handler to catch ItemNotFoundError and return 404

Tests FastAPI exception handler registration beyond HTTPException. A strong answer covers creating a custom exception, using app.exception_handler, and returning a JSONResponse with status 404 and a structured body. Red flag: per-route try/except, plain dict.

Python & FastAPI2 min read

Define a FastAPI endpoint with path and query parameters

Tests if you know FastAPI infers parameter location from the route string. Good answer: route with {item_id}, signature item_id: int, q: str | None = None, noting any param not in the path becomes a query param.

Python & FastAPI2 min read

How would you use a Pydantic response_model to enforce output structure?

Tests separation of internal models from API contracts. Define a Pydantic output model with only safe fields, set it as the endpoint response_model, and let FastAPI filter and validate.

Python & FastAPI2 min read

How do you prevent password_hash from appearing in a FastAPI response?

Tests FastAPI response filtering and the security practice of separating DB schemas from API contracts. A strong answer proposes a dedicated output model omitting the field, then cites response_model_exclude. Red flag: manual dict deletion or monkey-patching.

Python & FastAPI2 min read

How does Pydantic handle extra JSON fields, and how to configure it?

This tests Pydantic's data filtering behavior and configuration. By default, Pydantic ignores extra fields silently. Set model_config = ConfigDict(extra='forbid' or 'allow') to change it. A red flag is claiming FastAPI 422s by default on unknown fields.

Python & FastAPI2 min read

How do you define a Pydantic model for FastAPI request body validation?

Subclass BaseModel with id int, email str, full_name str|None; pass it as a route param so FastAPI validates JSON and returns 422s. Schema validation via Python type hints. Saying manual request.json() parsing.

Python & FastAPI2 min read

What standard and code elements power FastAPI's auto-generated API docs?

Tests whether you know FastAPI uses the OpenAPI standard and extracts metadata from Python type hints, Pydantic models, decorators, and docstrings to build interactive docs. Red flag: claiming you must manually maintain a separate schema file.

Python & FastAPI2 min read

How does FastAPI distinguish required optional and default query parameters

Tests whether you know FastAPI infers query parameter optionality from Python signature defaults. Answer: no default means required, Optional[T] = None means optional, T = value sets a default, with all three in one signature.

Python & FastAPI2 min read

Explain Python type hints and their importance in FastAPI

Define hints as declarations; explain FastAPI uses them with Pydantic to validate requests and OpenAPI docs. If you know FastAPI uses type hints for validation and docs. Seeing hints as IDE-only.

Python & FastAPI2 min read

Overriding FastAPI's OpenAPI Generator

FastAPI lets you swap app.openapi to reshape its generated schema without forking. Use this for vendor extensions, filtered operations, or merging external schemas. Forgetting to cache the result means every docs request rebuilds it and destroys performance.

Go & Rust2 min read

What is the purpose of the internal directory in Go?

Tests Go visibility boundaries beyond exported vs unexported. A strong answer states that internal is compiler-enforced module privacy, while lowercase is only package-private. Red flag: calling internal a naming convention rather than a build boundary.

Go & Rust2 min read

What type replaces String for read-only function parameters in Rust?

Use &str; it borrows without ownership, accepts literals and String via coercion, and avoids clones. Knowledge of Rust's read-only string view and API ergonomics.

Data Science & Analytics2 min read

Design a rate-limited REST API data collection script

Tests client-side throttling discipline versus reactive 429 handling. Strong answers proactively pace calls using rate-limit headers, cap concurrency, and apply exponential backoff with jitter. Red flag: tight-loop retries or ignoring headers.

Content & Copywriting2 min read

Structure a 5-minute video script demonstrating a new API endpoint

Tests your ability to sequence technical information for developers with limited attention. Strong outline: 60s problem hook, 90s live request demo, 60s auth and errors, 30s next steps. Red flag: opening with PRD specs before a working call.

Content & Copywriting2 min read

Design a simple templating system for ad copy generation

Tests separation of concerns and API design. A good answer: data model separate from template, placeholder syntax, graceful missing-value handling, and HTML escaping. Red flag: naive string concatenation without validation or extensibility.

Content & Copywriting2 min read

Design a content gap tool: data sources and core logic

Tests system design for SEO pipelines. Strong answers cite APIs (Ahrefs, Semrush, GSC), explain normalization, and frame logic as a left-anti-join on keyword plus geo and device filtered by rank. Red flag: dismissing API cost, rate limits, and freshness.

Content & Copywriting2 min read

Design architecture for multi-channel article distribution from a single source of truth

Tests separation of content and presentation via headless CMS. Strong answers cite a central structured CMS, content API, channel-specific rendering layers, and webhook push. Red flag: manual duplication or direct database sharing without API abstraction.

Content & Copywriting2 min read

Design a content versioning system with history and revert

Versions table with article_id, version_num, content_snapshot, timestamp; APIs for createVersion, getHistory, restoreVersion. Can you model immutable history simply? Diff-only storage without latest lookup or mutating rows in place.

CI/CD & Automation2 min read

What problem can a breaking API change cause during a rolling update?

Tests if you know rolling updates run mixed versions, so breaking API changes crash cross-traffic. Good answer: note old and new pods serve together, watch probes fail, and monitor 5xx spikes. Red flag: claiming Kubernetes isolates versions during rollout.

Android & Kotlin2 min read

Explain Kotlin's declaration-site variance with in and out

Out T means covariant producer (read), in T means contravariant consumer (write), removing wildcard noise. Understanding declaration-site variance versus wildcards. Confusing in/out with bounds or claiming immutability.

Android & Kotlin2 min read

Kotlin's Type-Safe Builders: Code as Data

Type-safe builders use Kotlin code to create a custom language (DSL) for building complex objects. It's like writing HTML, but the compiler validates your structure. This is common for UI layouts or server configs. The footgun is omitting `@DslMarker`.

Get API Design bites daily.

Five a day, five minutes, offline. With quizzes so it sticks.

Open testing — you’ll join as an early tester.