Basic query parameter declaration
📖 Scenario: You are building a simple web API using FastAPI. Your API will greet users by their name, which will be provided as a query parameter in the URL.
🎯 Goal: Create a FastAPI app that accepts a query parameter called name and returns a greeting message including that name.
📋 What You'll Learn
Create a FastAPI app instance named
appDefine a GET endpoint at path
/greetDeclare a query parameter named
name of type str in the endpoint functionReturn a dictionary with a key
message and value "Hello, {name}!" where {name} is the query parameter value💡 Why This Matters
🌍 Real World
APIs often need to accept user input via query parameters to customize responses, such as filtering data or personalizing messages.
💼 Career
Understanding how to declare and use query parameters in FastAPI is essential for backend developers building web APIs.
Progress0 / 4 steps