DS205 2024-2025 Legacy Icon

πŸ—£οΈ Week 02 Lecture

REST APIs and Introduction to FastAPI

Author
Published

27 January 2025

Last Updated: 26 January 2025, 22:20.

Welcome to Week 02 of DS205, where we will explore how to transition from data exploration to serving data through APIs.

πŸ“ Session Details

  • Date: Monday, 27 January 2025
  • Time: 10:00 am - 12:00 pm
  • Location: KSW.1.01

πŸ—£οΈ Lecture Content

1. Recap of Week 01

  • Discuss how easy/difficult it was to explore the ASCOR dataset independently.
  • Capture any sources of confusion about Python and pandas that needs to be reviewed in the course (if any is mentioned).

2. Introduction to REST APIs

  • What are APIs?
    • Definition and purpose.
  • Key concepts:
    • All the layers (client, server, etc.)
    • RESTful design: Resources, endpoints, HTTP methods.
    • JSON response structure: Flat vs nested.
    • Status codes: 200, 404, 500.

Visual Aids: Diagram showing the structure of RESTful API communication.

3. FastAPI Overview

  • Key features: Type hints, automatic validation, async support.
  • Code examples:
    • A simple "hello world" API.
    • Launching a basic FastAPI app with Uvicorn.
    • Demonstrating the auto-generated documentation at /docs.

4. Building blocks of a simple API

  • Endpoints: Define the structure of the API.
  • Models: Define the data structure for request and response bodies.
  • Routes: Define the URL paths for the endpoints.

5. Designing APIs for ASCOR Data

  • If time allows, a brainstorming session on designing an API for the ASCOR dataset.
  • Otherwise, group discusses the following API endpoints:
    • /v1/indicators: Serve indicators across all countries.
    • /v1/country-data: Return emission trends for a selected country.
  • Discuss user technical requirements and potential use cases.

🎬 Lecture Slides

Use keyboard arrows to navigate. Select the slides below or view fullscreen.

Or download the slides directly as a PDF:

πŸ‘‰ Next Steps

  1. Gain more knowledge depth by browsing the FastAPI Official Tutorial.
  2. Access the πŸ’» W02 Lab materials to see how we will practice building APIs

πŸŽ₯ Session Recording

Let’s hope the lecture capture works this time! 🀞 If there are no issues, I’ll make the lecture recording available on Moodle on the afternoon of the lecture.