Skip to content

Latest commit

 

History

History
81 lines (51 loc) · 5.27 KB

File metadata and controls

81 lines (51 loc) · 5.27 KB

Reading Material Python Week 2

The goal is to build a basic RESTful API in Python using FastAPI and validate data with Pydantic.

What is an API?

Before we start – a little refresher on APIs!

An API (Application Programming Interface) is a set of rules that allows different software applications to communicate with each other. Think of it as a waiter in a restaurant: you (the client) order food, the waiter (API) takes your order to the kitchen (server), and brings back your meal. In web development, APIs serve as the bridge between frontend applications (websites, mobile apps) and backend services (databases, business logic). APIs are essential because they enable separation of concerns, platform independence (one API serving web and mobile), scalability, reusability across multiple applications, and integration between different services. For example, in a museum website, the frontend displays artworks to users, the API handles requests like "get all Rembrandt paintings," and the backend manages the database.

Why FastAPI?

FastAPI is our framework of choice because it's one of the fastest Python frameworks available, offering performance comparable to Node.js and Go. It provides an excellent developer experience with automatic interactive documentation (at /docs and /redoc), built-in data validation using Pydantic models, type safety with Python type hints, and intuitive design that's easy to learn. FastAPI leverages modern Python features like async/await for high-performance applications, includes built-in security features, and offers excellent IDE support with autocompletion and error detection. This combination of speed, developer-friendly features, and modern Python capabilities makes FastAPI perfect for building robust, well-documented APIs.

There are other widely used frameworks such as Django and Flask. Feel free to explore them in your own time after you are done with this module!

Section 0: Review

Make sure you are familiar with RESTful APIs and HTTP Protocols

Review the Python types and virtual environments on the FastAPI page. These pages are specifically targeted to help set yourself up to work with FastAPI.

Section 1: (More) Advanced Python

These are more advanced topics which are needed in order to use FastAPI and Pydantic.

  1. Classes and Object-Oriented Programming (OOP) basics: A refresher from the basics
  2. OOP: Inheritance and Composition
  3. Requests
  4. Decorators
  5. Environment Variables

Section 2: FastAPI

Core FastAPI Concepts

  1. Getting Started with FastAPI

  2. Request and Response Handling

  3. Data Validation with Pydantic

  4. Advanced Features

Practical Resources

Key Learning Objectives

By the end of this week, you should be able to:

  • Create a basic FastAPI application with multiple endpoints
  • Use Pydantic models for request/response validation
  • Handle different HTTP methods (GET, POST, PUT, DELETE)
  • Implement path and query parameters
  • Add basic error handling and status codes
  • Test your API using the interactive documentation

Finished?

Check out this great tutorial which deconstructs the ins and outs of FastAPI.