Skip to content

Latest commit

 

History

History
98 lines (81 loc) · 3.66 KB

File metadata and controls

98 lines (81 loc) · 3.66 KB

### RESTful API with Python 3 and FastAPI ### https://github.com/nanotaboada/python-samples-fastapi-restful ### ### Requires the REST Client extension for VS Code: ### https://marketplace.visualstudio.com/items?itemName=humao.rest-client ### ### Key design note: ### squad_number = natural key (domain-meaningful, used for all CRUD operations) ### id (UUID) = surrogate key (internal, opaque, used for GET by id only)

@baseUrl = http://localhost:9000

# ------------------------------------------------------------------------------ # Health # ------------------------------------------------------------------------------

### GET /health/ — liveness check GET {{baseUrl}}/health/ Accept: application/json

# ------------------------------------------------------------------------------ # POST /players/ — Create # Giovani Lo Celso (squad 27): not seeded in the database, used as the creation # fixture. No id in the body; the server generates a UUID v4 on creation. # ------------------------------------------------------------------------------

### POST /players/ — Create a new Player POST {{baseUrl}}/players/ Content-Type: application/json

{
"firstName": "Giovani", "lastName": "Lo Celso", "dateOfBirth": "1996-07-09T00:00:00.000Z", "squadNumber": 27, "position": "Central Midfield", "abbrPosition": "CM", "team": "Real Betis Balompié", "league": "La Liga", "starting11": false

}

# ------------------------------------------------------------------------------ # GET /players/ — Retrieve all # ------------------------------------------------------------------------------

### GET /players/ — Retrieve all Players GET {{baseUrl}}/players/ Accept: application/json

# ------------------------------------------------------------------------------ # GET /players/{player_id} — Retrieve by UUID (surrogate key, internal) # Lionel Messi (squad 10): UUID v5, seeded by seed_001. # ------------------------------------------------------------------------------

### GET /players/{player_id} — Retrieve a Player by UUID GET {{baseUrl}}/players/acc433bf-d505-51fe-831e-45eb44c4d43c Accept: application/json

# ------------------------------------------------------------------------------ # GET /players/squadnumber/{squad_number} — Retrieve by Squad Number (natural key, domain) # Preferred lookup for external consumers. # ------------------------------------------------------------------------------

### GET /players/squadnumber/{squad_number} — Retrieve a Player by Squad Number GET {{baseUrl}}/players/squadnumber/10 Accept: application/json

# ------------------------------------------------------------------------------ # PUT /players/squadnumber/{squad_number} — Update # Damián Martínez (squad 23): seeded by seed_001. Updates firstName Damián → # Emiliano and clears middleName. # ------------------------------------------------------------------------------

### PUT /players/squadnumber/{squad_number} — Update an existing Player PUT {{baseUrl}}/players/squadnumber/23 Content-Type: application/json

{
"firstName": "Emiliano", "middleName": null, "lastName": "Martínez", "dateOfBirth": "1992-09-02T00:00:00.000Z", "squadNumber": 23, "position": "Goalkeeper", "abbrPosition": "GK", "team": "Aston Villa FC", "league": "Premier League", "starting11": true

}

# ------------------------------------------------------------------------------ # DELETE /players/squadnumber/{squad_number} — Delete # Giovani Lo Celso (squad 27): created by POST above. # ------------------------------------------------------------------------------

### DELETE /players/squadnumber/{squad_number} — Delete an existing Player DELETE {{baseUrl}}/players/squadnumber/27