All jobs / Backend developer / Backend Languages
Backend developer interview question · 0–1 years
The interviewer asks: “How should a FastAPI path operation be structured?” Strongest answer?
The strongest answer
Declare the route, verb and response model. Let Pydantic validate input; the function calls a service and returns a model — I don't grow SQLAlchemy queries inside the route.
Why it works
Exactly. The path operation is the HTTP edge. Types and models catch bad input; services own the use case.
What a good answer covers
- Path ops are the HTTP edge.
- Pydantic validates; a service does the work.
- Keep the response model explicit.
- Never execute client SQL.
Answers that fall short
- Close, but not the strongest: FastAPI functions are the API — they take a dict and return a dict.
Dict-in, dict-out works until a field is renamed. Response models are the contract you can test. - Weak: Disable Pydantic validation in production for speed.
Validation is the cheap security and the cheap 400. Turning it off to “go faster” ships 500s and injection. - Red flag: Run user-supplied SQL through sqlalchemy.text(request.query) so analysts can explore.
User SQL is injection with extra steps. Give analysts a warehouse account, not your OLTP API.
Who gets asked this
More Backend Languages questions
- A Node service that normally answers in 20 ms starts timing out on every endpoint whenever one particular…
- def add(item, bag=[]): bag.append(item); return bag — you call add(1) then add(2). What comes back the second…
- You pass a class instance and a struct to a method and both are modified inside. What does the caller see?
- When would you choose a tuple over a list?
- What is the most common cause of a NullReferenceException in a new codebase?
- What is the difference between == and is?
- When do you use an array rather than a List<T>?
- You want a value from a dict, or a default if the key is missing, without raising. What do you use?