# Week 1

## Week 1

Join the github classroom assignment with the following link: [https://classroom.github.com/a/KOc7f0j5](https://classroom.github.com/a/KOc7f0j5)

Once you join your repository will be created [https://github.com/blueprint-learn/week1-techteam-sp26-{github-username}](https://github.com/blueprint-learn/week1-techteam-sp26-miguel-merlin)

You will get an email with access to your repo

Clone your repo

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

**Goal for today**

> By the end of this class, you will understand what an API is <span class="s1">**and**</span> you will have written and run a real backend service.

**Set expectations**

- This is *not* web dev with HTML
- This is backend infrastructure
- What we build today looks simple, but it’s the same pattern used by Netflix, Stripe, AWS, etc.

#### **1. What Is an API?** 

**Core idea**

- API = *contract* between a client and a server
- You ask for data → server responds with data

```
Client (browser / app / script)
        |
        |  HTTP request
        v
      API Server
        |
        |  JSON response
        v
      Client
```

**Key clarification**

- APIs don’t care *who* the client is
- Browser, mobile app, another server — all the same

**Examples**

- Instagram feed
- Spotify playlists
- Google Maps directions

#### **2. REST &amp; HTTP Basics**

**REST (high-level)**

- Everything is a *resource*
- Each resource has a URL

**HTTP Methods**

<table id="bkmrk-method-meaning-get-r"><thead><tr><th>**Method**

</th><th>**Meaning**

</th></tr></thead><tbody><tr><td>GET

</td><td>Read data

</td></tr><tr><td>POST

</td><td>Create data

</td></tr><tr><td>PUT

</td><td>Update data

</td></tr><tr><td>DELETE

</td><td>Remove data

</td></tr></tbody></table>

**HTTP Response**

- Status code (200, 404, etc.)
- Body (usually JSON)

```json
{
  "id": 3,
  "name": "Notebook",
  "price": 5.99
}
```

**Important**

- JSON ≠ Python dictionary (but very similar)

#### **3. Live Demo Setup**

```
pip3 install -r requirements.txt
```

Minimal app

```python
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def root():
    return {"message": "Hello World"}
```

Run the app

```bash
uvicorn app.main:app --reload
```

#### **4. Endpoints &amp; Path Parameters**

```python
@app.get("/items/{item_id}")
def read_item(item_id: int):
    return {"item_id": item_id}
```

- Automatic validation
- Type validation