GET işlemleri

FastAPI'ye Giriş

Matt Eckerle

Software and Data Engineering Leader

GET işlemi özeti

HTTP protokolü - birden çok işlem türü

  • En yaygını GET’tir

Örnek: https://www.google.com:80/search?q=fastapi

Bir GET isteğinin temel parçaları:

  • Host, ör. www.google.com
  • Port, ör. 80 (varsayılan)
  • Yol (Path), ör. /search
  • Sorgu dizgesi (Query String), ör. ?q=fastapi
FastAPI'ye Giriş

FastAPI GET işlemi

En basit FastAPI uygulaması:

from fastapi import FastAPI

# Uygulamayı başlat app = FastAPI()
# Kök için GET isteklerini işle @app.get("/") def root(): return {"message": "Hello World"}
1 https://fastapi.tiangolo.com/tutorial/first-steps/
FastAPI'ye Giriş

cURL web istemcisini kullanma

Temel cURL seçenekleri:

$ curl -h
Usage: curl [options...] <url>
 -v, --verbose               Make the operation more talkative
 -H, --header <header/@file> Pass custom header(s) to server
 -d, --data <data>           HTTP POST data

Örnek kullanım:

$ curl http://localhost:8000
{"message":"Hello World"}
FastAPI'ye Giriş

Sorgu Parametreleri

Yeni uç nokta:

  • Yol: "/hello"
  • Sorgu parametresi: "name"
    • Varsayılan: "Alan"
@app.get("/hello")
def hello(name: str = "Alan"):
    return {"message": f"Hello {name}"}

İstekte ad yoksa: Ad verilmeden yapılan bir curl isteğini gösteren terminal. Yanıt mesajı: "Hello Alan."

İstekte ad varsa: Ad verilerek yapılan bir curl isteğini gösteren terminal. Yanıt mesajı: "Hello Steve."

FastAPI'ye Giriş

Hadi pratik yapalım!

FastAPI'ye Giriş

Preparing Video For Download...