Skip to content
tezvyn:

API

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

React Native2 min read

GraphQL: Ask for Exactly What You Need

GraphQL lets clients request exactly the data they need from a single endpoint, avoiding over-fetching. It's ideal for mobile apps, but beware of the N+1 problem where one query can trigger many database lookups on the backend.

React Native2 min read

Axios Interceptors: Middleware for Your API Calls

Axios Interceptors are like middleware for your API calls, letting you globally modify requests before they're sent or responses before they're handled. Use them to inject auth tokens or log activity. The footgun: request interceptors run last-in-first-out.

React Native2 min read

React Native: Making Network Requests with Fetch

fetch is your app's tool for requesting server data. It's asynchronous, returning a promise for a future response. Use it for API calls like loading profiles or posting updates. The footgun: always `catch` errors, or they will fail silently.

React Native2 min read

React Native's Dimensions API: The Manual Approach

React Native's `Dimensions` API is a low-level way to get a one-time snapshot of screen or window sizes. Use it outside React components or when you need to subscribe to changes manually. The footgun is caching its value, as it won't update on rotation.

React Native2 min read

Platform.select: Write Once, Adapt Anywhere

Platform.select is a switch statement for your UI, letting you apply styles or components for iOS and Android from one object. It's ideal for tweaking styles in StyleSheet.create or rendering different components. The footgun is forgetting a `default` key.

Python & FastAPI2 min read

FastAPI's StreamingResponse: Send Data in Chunks

StreamingResponse sends data piece by piece, like a live broadcast, instead of sending a complete file all at once. This keeps your server's memory low for huge responses like file downloads, video streams, or live data from AI models.

Python & FastAPI2 min read

FastAPI: Validating Models with Pydantic's Field

Pydantic's `Field` adds guardrails directly to your data model's attributes. Use it to enforce constraints like string length (`max_length=50`) or numeric ranges (`gt=0`), making your models self-validating.

Python & FastAPI2 min read

FastAPI Lifespan: Code Before Startup, After Shutdown

FastAPI's lifespan events are "open for business" and "closing time" routines that run once before startup and after shutdown. Use them to initialize a DB pool or load a model. The footgun is putting request-specific logic here; it runs once only.

Python & FastAPI1 min read

Customizing FastAPI's Swagger UI Behavior

Treat FastAPI's Swagger UI as a configurable frontend, not a static page. You can customize its behavior by passing a dictionary of settings on app startup. This is useful for changing themes or pre-filling auth fields. The footgun: keys must be camelCase.

Python & FastAPI1 min read

Exclude a FastAPI Endpoint from OpenAPI Docs

Hide an endpoint from your API docs by setting `include_in_schema=False`. Use this for internal or deprecated endpoints. The footgun: this only hides the endpoint from documentation; it remains fully functional and accessible if the URL is known.

Python & FastAPI2 min read

FastAPI: Documenting Additional API Responses

Document every possible API response, not just the happy path. The `responses` decorator parameter lets you define alternative status codes and schemas, like a 404 error model, making your OpenAPI docs complete.

Python & FastAPI2 min read

FastAPI: Configure API Metadata for Better Docs

Think of FastAPI metadata as your project's business card. It sets the title, version, and description in your auto-generated docs, making your API professional and discoverable. The main footgun is forgetting to update the version string after a release.

Python & FastAPI2 min read

CSRF: Double Submit Cookies for Stateless Backends

Double Submit Cookies stop CSRF by requiring a secret in two places: a cookie and a request header. The server just checks if they match. It's useful for stateless APIs where storing server-side tokens is impractical.

Python & FastAPI2 min read

Refresh Tokens: Persistent Sessions Without Re-Authentication

A refresh token is a long-lived credential used to get a new, short-lived access token without re-authenticating. It's how apps keep you logged in for weeks. The footgun is storing it insecurely, letting attackers mint access tokens forever.

Python & FastAPI2 min read

API Keys: Simple Server-to-Server Authentication

An API key is a simple secret token a client sends to prove its identity, often in a request header. It's ideal for machine-to-machine communication where a user login flow is unnecessary. Footgun: Never send keys in URL query parameters.

Python & FastAPI1 min read

FastAPI: Splitting Your App with `include_router`

`app.include_router` is like plugging a pre-wired power strip of API endpoints into your main FastAPI app. It lets you organize a large app into smaller files by feature, then combine them. The footgun is forgetting to add a URL `prefix` for each router.

Python & FastAPI2 min read

FastAPI's APIRouter: Grouping Routes into Modules

Think of APIRouter as a mini-FastAPI app for organizing endpoints. It lets you group related paths, like all user routes, into a separate file. This is crucial for keeping large applications maintainable.

Python & FastAPI1 min read

Accessing the Raw Request Object in FastAPI

Think of it as dropping to a lower level. Instead of FastAPI handing you validated data, you grab the raw Starlette HTTP request yourself. Use this for data not covered by standard declarations, like a client's IP.

Python & FastAPI2 min read

FastAPI's Security Utility: Dependencies for Auth

FastAPI's `Security` utility is a specialized `Depends` for authentication. It signals to OpenAPI that a dependency is required for security, enabling interactive docs. Use it to protect endpoints by injecting the authenticated user.

Python & FastAPI2 min read

FastAPI Global Dependencies: DRY Your API Logic

A FastAPI global dependency is like a bouncer for your entire API, running a check on every request. Use it for universal concerns like API key validation. The footgun is applying logic that should only affect a subset of routes, making your API rigid.

Python & FastAPI2 min read

FastAPI's Dependency Caching: One Request, One Call

FastAPI dependencies are singletons for the life of a request. If multiple parts of your code ask for the same dependency (e.g., a database session), FastAPI runs it once, caches the result, and shares it. The footgun: this cache is per-request, not global.

Python & FastAPI2 min read

FastAPI: Using Classes as Dependencies

Bundle related request parameters into a class instead of repeating them in every endpoint. FastAPI automatically creates an instance for you, cleaning up your code. This is ideal for shared logic like pagination. The footgun: FastAPI injects into `__init__`.

Python & FastAPI2 min read

FastAPI's Depends: Let the Framework Handle Setup

Think of `Depends` as a pre-flight checklist for your API endpoints. You list required setup tasks, like getting a user or a database session, and FastAPI runs them for you. This is key for sharing logic like auth or database connections across many routes.

Python & FastAPI2 min read

FastAPI: Setting Custom Response Headers

Set custom HTTP headers in FastAPI by adding a `Response` parameter to your endpoint. This lets you add metadata like trace IDs without changing your return data. The footgun is thinking you must return the `Response` object; just return your data as usual.

Get API bites daily.

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

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