0Pricing
FastAPI Backend Development Bootcamp · Lekcja

Pierwszy endpoint API

Nauczą się Państwo tworzyć proste endpointy GET, definiować trasy i zwracać podstawowe odpowiedzi JSON.

Pierwszy endpoint API to bezpłatna lekcja FastAPI Backend Development Bootcamp na CoddyKit. To lekcja 2 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej FastAPI Backend Development Bootcamp, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs FastAPI Backend Development Bootcamp zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

What's an API Endpoint?

An API endpoint is a specific URL your API exposes — an address that receives requests and returns a service. We start with GET, used to fetch data.

Your FastAPI Application

Every app starts from a FastAPI instance, conventionally named app. This object is the core where all your routes and logic live.

from fastapi import FastAPI

app = FastAPI()

# This 'app' object is where your API lives!

Defining Routes with Decorators

FastAPI uses decorators to bind a URL path to a function. @app.get("/") says: on a GET to the root path, run the function below.

Your First 'Hello World' Endpoint

Here is the classic API Hello World — a single GET endpoint at /. Run it and hit the root in your browser or Postman.

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Hello, CoddyKit!"}

# To run: Save as main.py, then 'uvicorn main:app --reload'

Running Your FastAPI App

Run your app with Uvicorn: uvicorn main:app --reload finds app in main.py and auto-restarts whenever you edit code.

FastAPI's JSON Magic

FastAPI's JSON magic: return a Python dict or list and it serializes to a JSON response automatically — no manual conversion needed.

Returning Structured JSON Data

Return a richer Python dict and FastAPI ships it as structured JSON. Here, an endpoint hands back full product details.

from fastapi import FastAPI

app = FastAPI()

@app.get("/product")
def get_product_info():
    return {
        "id": "CK001",
        "name": "CoddyKit Pro Course",
        "price": 49.99,
        "available": True
    }

# Run with: uvicorn main:app --reload
# Access this endpoint at /product

Creating Multiple Endpoints

An API has many endpoints, each for a different resource. Define as many as you need on one app — here, two distinct GET routes.

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def read_root():
    return {"message": "Welcome to our API!"}

@app.get("/items")
def get_items():
    return [
        {"id": 1, "name": "Laptop"},
        {"id": 2, "name": "Mouse"},
        {"id": 3, "name": "Keyboard"}
    ]

# Run with: uvicorn main:app --reload
# Access at / and /items

Endpoint Naming Conventions

Good endpoint naming keeps an API readable: plural nouns for collections, short lowercase hyphenated paths, and no verbs — the HTTP method implies the action.

Quick Check

Which of the following code snippets correctly defines a FastAPI GET endpoint at the path /status that returns a JSON object {"status": "OK"}?

Lesson Summary

Solid! You built endpoints with decorators, returned dicts as JSON, and ran the app via Uvicorn. Next: making routes dynamic with URL data.

Często zadawane pytania

Czy lekcja „Pierwszy endpoint API” jest bezpłatna?

Tak — pełny tekst „Pierwszy endpoint API” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu FastAPI Backend Development Bootcamp, przejdź na CoddyKit PRO. Kurs FastAPI Backend Development Bootcamp zawiera 4 lekcji w sumie.

Co nauczysz się w „Pierwszy endpoint API”?

Nauczą się Państwo tworzyć proste endpointy GET, definiować trasy i zwracać podstawowe odpowiedzi JSON. Ćwiczysz FastAPI Backend Development Bootcamp z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć FastAPI Backend Development Bootcamp?

Nie wymagamy żadnego doświadczenia. FastAPI Backend Development Bootcamp w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 2 z 4.

Ile czasu zajmuje lekcja „Pierwszy endpoint API”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji FastAPI Backend Development Bootcamp?

Tak. Każda lekcja FastAPI Backend Development Bootcamp zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Wprowadzenie do FastAPI i konfiguracja
  2. Pierwszy endpoint API
  3. Parametry ścieżki i zapytania
  4. Interaktywna dokumentacja API ze Swagger UI
← Powrót do FastAPI Backend Development Bootcamp