0Pricing
FastAPI Backend Development Bootcamp · Ders

Üst Bilgiler, Çerezler ve Özel Yanıtlar

İstek üst bilgilerini ve çerezleri okuyun, bunları yanıtlara ekleyin ve FastAPI'de düz metin, HTML, yönlendirme ve akış gibi özel yanıt türleri döndürün.

Üst Bilgiler, Çerezler ve Özel Yanıtlar, CoddyKit'te ücretsiz bir FastAPI Backend Development Bootcamp dersidir. Bu, 4 dersinin 4. 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.

Beyond the JSON Body

Request and response handling involves more than the JSON body. Headers and cookies carry metadata like auth tokens, content negotiation, and sessions. FastAPI gives you typed access to both.

Reading a Header

Declare a parameter with Header to read an incoming header. FastAPI auto-converts user_agent to the User-Agent header name.

from fastapi import FastAPI, Header

app = FastAPI()

@app.get('/info')
async def info(user_agent: str = Header(default=None)):
    return {'ua': user_agent}

Reading Cookies

Use Cookie to read a named cookie, just like headers and query params.

from fastapi import Cookie

@app.get('/session')
async def session(session_id: str = Cookie(default=None)):
    return {'session': session_id}

Setting Headers on a Response

Inject a Response object to set headers while still returning normal data.

from fastapi import Response

@app.get('/items')
async def items(response: Response):
    response.headers['X-Total-Count'] = '42'
    return ['a', 'b']

Setting Cookies

Call response.set_cookie to send a cookie back to the client. Add flags like httponly and secure for safety.

@app.post('/login')
async def login(response: Response):
    response.set_cookie('session_id', 'abc123', httponly=True, secure=True)
    return {'ok': True}

Plain Text and HTML Responses

Return non-JSON content with specialized response classes.

from fastapi.responses import PlainTextResponse, HTMLResponse

@app.get('/text', response_class=PlainTextResponse)
async def text():
    return 'hello'

@app.get('/page', response_class=HTMLResponse)
async def page():
    return '<h1>Hi</h1>'

Redirects

Send the client elsewhere with RedirectResponse. Choose the status code for permanent vs temporary redirects.

from fastapi.responses import RedirectResponse

@app.get('/old')
async def old():
    return RedirectResponse(url='/new', status_code=301)

Header Name Conversion

FastAPI converts underscores in parameter names to hyphens for headers. This pure example shows the same idea.

def to_header_name(param):
    return '-'.join(w.capitalize() for w in param.split('_'))
print(to_header_name('user_agent'))
print(to_header_name('x_api_key'))

Streaming Responses

For large or generated data, stream it with StreamingResponse so you do not buffer everything in memory.

from fastapi.responses import StreamingResponse

def rows():
    for i in range(3):
        yield f'row {i}\n'

@app.get('/export')
async def export():
    return StreamingResponse(rows(), media_type='text/plain')

Custom Status Codes

Set a default status for an operation with the status_code argument, or override per request via the injected Response.

from fastapi import status

@app.post('/items', status_code=status.HTTP_201_CREATED)
async def create():
    return {'created': True}

Security Notes

When setting auth cookies, prefer httponly=True (blocks JS access), secure=True (HTTPS only), and samesite to mitigate CSRF.

Quick Check

You declare x_api_key: str = Header(). Which incoming HTTP header does FastAPI map this to?

Recap

You handled the full request/response surface:

  • Read headers and cookies with Header and Cookie.
  • Set headers and cookies via the injected Response.
  • Returned plain text, HTML, redirects, and streaming responses.
  • Applied secure cookie flags and custom status codes.

Sıkça Sorulan Sorular

“Üst Bilgiler, Çerezler ve Özel Yanıtlar” dersi ücretsiz mi?

Evet — “Üst Bilgiler, Çerezler ve Özel Yanıtlar” 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.

“Üst Bilgiler, Çerezler ve Özel Yanıtlar” dersinde ne öğreneceğim?

İstek üst bilgilerini ve çerezleri okuyun, bunları yanıtlara ekleyin ve FastAPI'de düz metin, HTML, yönlendirme ve akış gibi özel yanıt türleri döndürün. 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 4. dersidir.

“Üst Bilgiler, Çerezler ve Özel Yanıtlar” 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

  1. İstek Gövdesi için Pydantic Modelleri
  2. Yanıt Modelleri ve Durum Kodları
  3. Form Verileri ve Dosya Yüklemeleri
  4. Üst Bilgiler, Çerezler ve Özel Yanıtlar
← FastAPI Backend Development Bootcamp Sayfasına Dön