Bird
0
0

Which of the following is the correct syntax to define a PUT route in FastAPI for updating an item with an ID?

easy📝 Syntax Q3 of 15
FastAPI - Database Integration
Which of the following is the correct syntax to define a PUT route in FastAPI for updating an item with an ID?
A@app.post('/items/{item_id}') async def update_item(item_id: int, item: Item): return item
B@app.get('/items/{item_id}') async def update_item(item_id: int, item: Item): return item
C@app.delete('/items/{item_id}') async def update_item(item_id: int, item: Item): return item
D@app.put('/items/{item_id}') async def update_item(item_id: int, item: Item): return item
Step-by-Step Solution
Solution:
  1. Step 1: Identify HTTP method for update

    PUT is the standard method to update existing resources.
  2. Step 2: Check route and function signature

    Route uses /items/{item_id} with @app.put and async function with parameters item_id and item.
  3. Final Answer:

    @app.put('/items/{item_id}') async def update_item(item_id: int, item: Item): return item -> Option D
  4. Quick Check:

    PUT route syntax correct = @app.put('/items/{item_id}') async def update_item(item_id: int, item: Item): return item [OK]
Quick Trick: Use @app.put with path param for updates [OK]
Common Mistakes:
MISTAKES
  • Using @app.get for update
  • Missing path parameter
  • Incorrect async function signature

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More FastAPI Quizzes