Building APIs with Python
You'll learn how the web talks in requests and responses, then design and write your own API endpoints in Python, step by step adding validation, clear errors, a SQL database, authentication, permissions and pagination, and finish by building a small backend of your own.
13 modules · 63 lessons · about 25 hours · Intermediate
What you'll be able to do
Build the backend for a web or mobile app: design and write my own API endpoints in Python, with validation, auth and a database.
- How a client and a server talk over HTTP, and how to picture every request and response as plain Python data.
- What GET, POST, PUT, PATCH and DELETE mean, and how status codes tell the client what happened.
- Reading and writing JSON in Python so your endpoints can accept and return structured data.
- Turning an app's features into resources, URLs and methods that are predictable and easy to use.
- Building the Python code behind endpoints: routing requests to handler functions and implementing create, read, update and delete.
- Checking everything a client sends before you trust it, and telling them exactly what to fix.
- Giving every failure a consistent, helpful response without leaking your server's internals.
- Designing tables for your resources and writing the SQL that creates, reads, updates and deletes them.
- Making your handlers store and load data through SQL safely from Python.
- Proving who is calling your API, with passwords stored safely and tokens on every request.
- Deciding what each signed-in user is allowed to see and change.
- Returning big lists in pages that clients can filter, sort and move through reliably.
- Putting everything together into a small, working backend of your own, and seeing how it maps to real frameworks.
Course outline
1Requests and responses
- Clients, servers and APIs
- Reading a URL
- Inside a request and a response
- Requests and responses as Python data
2Methods and status codes
- The main HTTP methods
- Safe and idempotent methods
- Status code families and success codes
- Client and server error codes
- Choosing the right status code
3JSON for APIs
- JSON and Python types
- Parsing and producing JSON
- Bad bodies and awkward values
- Shaping response bodies
4Designing a REST API
- Resources and URLs
- Mapping operations to methods
- Related resources, filters and sorting
- Actions and versions
- Writing an API contract
5Writing endpoint logic
- One handler per endpoint
- Routing requests with path parameters
- Reading query parameters and bodies
- Create and read endpoints
- Update and delete endpoints
- Keeping business logic out of handlers
6Validating input
- Required fields and types
- Ranges, lengths and formats
- Unknown fields and cleaning input
- Reporting every problem at once
- Partial updates and URL parameters
7Handling errors well
- A consistent error format
- From exceptions to responses
- Missing, conflicting and not allowed
- Unexpected errors and logging
8SQL for API data
- Querying the rows an endpoint needs
- Designing tables from resources
- Creating, changing and deleting rows
- Joining related resources
- Counts, filters and transactions
9Connecting endpoints to a database
- Running SQL from Python
- Parameterised queries and SQL injection
- A small data-access layer
- Database errors as API responses
- Database-backed endpoints
10Authentication
- Who is calling your API?
- Storing passwords safely
- Logging in and issuing tokens
- Checking bearer tokens
- Signed tokens that expire
11Authorization and permissions
- Roles and admin-only endpoints
- Checking ownership on every object
- Which fields a user may read and set
- Central permission checks and scoped queries
12Pagination, filtering and sorting
- Limit and offset pagination
- Page metadata and next links
- Cursor pagination
- Safe filtering and sorting
- A complete list endpoint
13Building a complete API
- Planning your notes API
- Storage and the data layer
- Endpoints with validation and errors
- Accounts, tokens and ownership
- Lists and tests
- From handlers to a real framework
How you'll learn
- Write and run real code in your browser. Nothing to install.
- Short lessons that build on each other, so every step makes sense.
- A tutor you can ask anytime. It knows the lesson you're on.
- Quick checks along the way, so you know it stuck.
Questions
How do I get Building APIs with Python?
It comes with any paid plan, along with every other course in the catalogue. Sign up, pick a plan and start.
Do I need any experience?
It helps to know the basics already. Each lesson builds on the one before, so you can go at your own pace.
How long does it take?
63 lessons in all, about about 25 hours in total. Go at your own pace: your progress is saved.
What if I get stuck?
Ask the tutor. It knows the lesson you're on and explains things another way until it clicks.
Can I learn on my phone?
Yes. Lernelle works in any browser, on your phone, tablet or computer.
Does it stay up to date?
Yes. We update the course when things change, and you can bring the new version into yours with one click.
Ready to start?
Pick a plan and this course is yours, with everything else in the catalogue.