Yol ve Sorgu Parametreleri
Yol parametrelerini kullanarak URL'lerden dinamik verileri nasıl alacağınızı ve isteğe bağlı sorgu parametrelerini nasıl işleyeceğinizi öğrenin.
Yol ve Sorgu Parametreleri, CoddyKit'te ücretsiz bir FastAPI Backend Development Bootcamp dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, FastAPI Backend Development Bootcamp öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. FastAPI Backend Development Bootcamp kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Dynamic URLs for APIs
APIs often carry data right in the URL — fetching a product by ID or filtering a list. FastAPI gives you clean ways to capture that. Let's dig in.
Meet Path Parameters
Path parameters are URL segments that pin down a specific resource, written in curly braces like /items/{item_id}. Perfect for one exact item.
Your First Path Parameter
Match a path segment to a function arg by name: /items/{item_id} maps to item_id. The type hint int auto-converts it.
from fastapi import FastAPI
app = FastAPI()
@app.get("/items/{item_id}")
async def read_item(item_id: int):
return {"item_id": item_id, "message": "Here is your item!"}Power of Type Hints
Type hints like item_id: int drive validation. Hit /items/abc and FastAPI returns a clean error automatically. Use str, int, float, bool, UUID.
Handling Multiple Paths
You can take several path parameters in one route. FastAPI matches them by name, so the order in your function signature doesn't matter.
from fastapi import FastAPI
app = FastAPI()
@app.get("/users/{user_id}/items/{item_id}")
async def read_user_item(user_id: int, item_id: str):
return {"user_id": user_id, "item_id": item_id}What are Query Parameters?
Query parameters are key-value pairs after a ?, like /items?skip=0&limit=10. They are optional — ideal for filtering, paging, or sorting.
Your First Query Parameter
Any function arg that is not in the path becomes a query parameter automatically. Here, skip and limit are typed integers.
from fastapi import FastAPI
app = FastAPI()
@app.get("/items/")
async def read_items(skip: int = 0, limit: int = 10):
return {"skip": skip, "limit": limit}Optional Queries & Defaults
Make a query parameter optional by giving it a default. For a None default, type it as Optional[str] so FastAPI knows it may be missing.
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/products/")
async def read_products(q: Optional[str] = None, page_size: int = 20):
results = {"page_size": page_size}
if q:
results.update({"search_query": q})
return resultsPath + Query Power
Combine both: path parameters are required, query parameters stay optional with defaults. FastAPI sorts out which is which seamlessly.
from typing import Optional
from fastapi import FastAPI
app = FastAPI()
@app.get("/users/{user_id}/orders/")
async def get_user_orders(user_id: int, status: Optional[str] = None, limit: int = 10):
return {"user_id": user_id, "status": status, "limit": limit, "message": "User orders fetched."}Quick Check on Parameters
Recap: Dynamic API Routes
Great work! You made routes dynamic with path parameters for required IDs, query parameters for optional filters, and type hints for free validation.
Sıkça Sorulan Sorular
“Yol ve Sorgu Parametreleri” dersi ücretsiz mi?
Evet — “Yol ve Sorgu Parametreleri” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve FastAPI Backend Development Bootcamp kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. FastAPI Backend Development Bootcamp kursu toplamda 4 dersten oluşur.
“Yol ve Sorgu Parametreleri” dersinde ne öğreneceğim?
Yol parametrelerini kullanarak URL'lerden dinamik verileri nasıl alacağınızı ve isteğe bağlı sorgu parametrelerini nasıl işleyeceğinizi öğrenin. FastAPI Backend Development Bootcamp ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
FastAPI Backend Development Bootcamp öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te FastAPI Backend Development Bootcamp, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.
“Yol ve Sorgu Parametreleri” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu FastAPI Backend Development Bootcamp dersinde kod yazıp çalıştırabilir miyim?
Evet. Her FastAPI Backend Development Bootcamp dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- FastAPI'ye Giriş ve Kurulum
- İlk API Uç Noktanız
- Yol ve Sorgu Parametreleri
- Swagger UI ile Etkileşimli API Belgeleri