0
0
FastAPIframework~15 mins

Route decorator syntax in FastAPI - Mini Project: Build & Apply

Choose your learning style9 modes available
Route decorator syntax
📖 Scenario: You are building a simple web API using FastAPI. You want to create routes that respond to HTTP requests.
🎯 Goal: Create a FastAPI app with a route that responds to GET requests at the path /hello and returns a greeting message.
📋 What You'll Learn
Create a FastAPI app instance named app
Define a route using the @app.get decorator for the path /hello
Create a function named hello that returns the string 'Hello, FastAPI!'
💡 Why This Matters
🌍 Real World
Web APIs use route decorators to define how the server responds to different URLs and HTTP methods.
💼 Career
Understanding route decorators is essential for backend developers working with FastAPI or similar web frameworks.
Progress0 / 4 steps
1
Create FastAPI app instance
Import FastAPI from fastapi and create an app instance called app.
FastAPI
Need a hint?

Use app = FastAPI() to create the app instance.

2
Add GET route decorator
Use the @app.get decorator with the path "/hello" above a function named hello.
FastAPI
Need a hint?

Write @app.get("/hello") just before defining def hello():.

3
Return greeting message
Inside the hello function, return the string 'Hello, FastAPI!'.
FastAPI
Need a hint?

Use return 'Hello, FastAPI!' inside the function.

4
Complete FastAPI route setup
Ensure the full code includes the import, app creation, route decorator, and function returning the greeting.
FastAPI
Need a hint?

Review the full code to confirm all parts are present.