How do you handle path parameters in Flask and FastAPI?
Answer
Flask: path parameters use angle brackets: @app.route('/users/<int:user_id>'). The function receives the parameter as a keyword argument: def get_user(user_id): .... Type converters: int, float, string, path, uuid. Flask validates the type automatically. FastAPI: path parameters use curly braces: @app.get('/users/{user_id}'). Declare the parameter in the function signature with a type hint: async def get_user(user_id: int): .... FastAPI uses the type hint for validation and converts the string to the declared type. You can also add validation with Path(): user_id: int = Path(..., gt=0, le=1000). Both frameworks return appropriate error responses for type mismatches.
Previous
What is FastAPI's dependency injection system?
Next
What is Flask's application context and request context?