Practice Bank: Building Web Apps & APIs — Flask & FastAPI
A deeper set of practice problems, organized by topic, for extra reps
beyond the main exercises — including scenario-based problems
written in the same style you'll meet in real interviews. Every task
here is a plain Python function or class modeling exactly what a real
Flask or FastAPI route function does with its inputs — no live
server or installed framework is needed anywhere in this bank. No
import beyond
json/os/re/math/datetime/random/csv/threading/concurrent.futures.
starter.py below and run
python3 starter.py from inside the same folder.
Topic 1: What a Web Framework Is & the Request/Response Cycle
1 Identify a request's method and path
Find # TODO 1.1. Write identify_method_and_path(request_line).
2 The shared cycle steps
Find # TODO 1.2. Write request_response_cycle_steps().
3 Debug the Code
Find # TODO 1.3. This claims a web framework compiles Python to machine code. Fix it.
Choosing a status code
Find # TODO 1.A. Write choose_status_code(outcome).
Why "localhost" still involves a network connection
Find # TODO 1.B. Write explain_localhost_still_networked().
Topic 2: Flask Routes and render_template
1 A route-to-function map
Find # TODO 2.1. Write build_route_map().
2 A render_context helper
Find # TODO 2.2. Write render_context(template_name, **context).
3 Debug the Code
Find # TODO 2.3. This view function never returns its result. Fix it.
Building a dashboard context
Find # TODO 2.A. Write build_dashboard_context(users, tasks).
What a view function's return value becomes
Find # TODO 2.B. Write explain_view_function_return_value().
Topic 3: The Flask Request Object
1 Reading a query parameter
Find # TODO 3.1. Write read_query_param(simulated_args, key, default="").
2 Reading a JSON field
Find # TODO 3.2. Write read_json_field(simulated_json_body, key, default=None).
3 Debug the Code
Find # TODO 3.3. This calls a form-only method on a plain dict standing in for a JSON body. Fix it.
Handling a search form
Find # TODO 3.A. Write handle_search_form(simulated_args).
request.args vs. request.form
Find # TODO 3.B. Write explain_args_vs_form().
Topic 4: FastAPI Path and Query Params
1 Converting a path parameter
Find # TODO 4.1. Write convert_path_param(raw_value, target_type).
2 Path vs. query classification
Find # TODO 4.2. Write classify_param(has_default, in_path_string).
3 Debug the Code
Find # TODO 4.3. This treats an optional query parameter as required. Fix it.
Building a filtering endpoint
Find # TODO 4.A. Write filter_by_status(orders, status=None).
What happens on a failed path param conversion
Find # TODO 4.B. Write explain_path_param_conversion_failure().
Topic 5: Pydantic Models and Automatic Docs
1 Checking required fields
Find # TODO 5.1. Write has_required_fields(body, required_fields).
2 Applying a default
Find # TODO 5.2. Write apply_default(body, field, default_value).
3 Debug the Code
Find # TODO 5.3. This accepts any truthy value as a boolean field. Fix it.
Designing a signup model
Find # TODO 5.A. Write validate_signup_data(body).
What generates /docs
Find # TODO 5.B. Write explain_docs_generation().
Topic 6: Flask vs. FastAPI, Side by Side
1 Recommending a framework
Find # TODO 6.1. Write recommend_framework_for(project_description).
2 Describing validation style
Find # TODO 6.2. Write describe_validation_style(framework_name).
3 Debug the Code
Find # TODO 6.3. This overstates that Flask cannot return JSON. Fix it.
Picking a framework for a new feature
Find # TODO 6.A. Write recommend_framework(needs_html_page, needs_automatic_docs).
The 30-second comparison
Find # TODO 6.B. Write elevator_pitch_flask_vs_fastapi().
Topic 7: What's Next — HTML, JSON, and Where React Fits
1 Classifying a response body
Find # TODO 7.1. Write classify_response_body(response_body).
2 Does this need a separate renderer?
Find # TODO 7.2. Write needs_something_else_to_render(response_body).
3 Debug the Code
Find # TODO 7.3. This claims a JSON API is a complete website by itself. Fix it.
Planning a new product's architecture
Find # TODO 7.A. Write recommend_architecture(needs_mobile_app, needs_multiple_frontends).
What a frontend does with a JSON API (conceptual only)
Find # TODO 7.B. Write explain_frontend_role_conceptually() — without teaching any React/JavaScript syntax.
solution.py. Your exact
wording doesn't need to match — the goal is that your program
runs without errors and does what each TODO asks. One exception:
Topic 3's debug task intentionally demonstrates a real
AttributeError before it's fixed — that's the
whole point of that task.