Skip to main content

Week 2

Week 2

Join the github classroom assignment with the following link: 

Once you join your repository will be created https://github.com/blueprint-learn/week2-techteam-sp26-{github-username}

You will get an email with access to your repo

Clone your repo

git clone https://github.com/blueprint-learn/week1-techteam-sp26-{github-username}.git

Recap last week

    We built a running FastAPI server

    We created endpoints

    We used path parameters

    CI tested our API contract

    Goal for today

    By the end of today, you will understand how APIs receive structured data and how FastAPI validates it automatically.

    Big idea

    Last week: Client asks for data

    This week: Client sends data

    1. How Data Enters an API

    There are three main ways data reaches an API:

    Path parameters

    /items/5

    Query parameters

    /items?limit=10

    Request body (JSON)

    Type

    Where used

    Example

    Path

    Identify resource

    /users/3

    Query

    Filter/search

    ?limit=10

    Body

    Send data

    POST JSON

    2. Query Parameters

    @app.get("/items")
    def list_items(limit: int = 10):
        return {"limit": limit}

    Show

      /items

      /items?limit=5

      /items?limit=abc

      Explain

        Default values

        Type conversion

        Automatic validation

        Key insight

        FastAPI parses query strings into typed Python values.

        3. Request Bodies & JSON

        Motivation

        Real APIs receive structured data:

          User signup

          Orders

          Messages

          Payments

          Example request

          {
            "name": "Notebook",
            "price": 5.99
          }

          Naive version

          @app.post("/items")
          def create_item(item: dict):
              return item

          Problem

            No validation

            No structure

            No guarantees