FastAPI Fundamentals
Dependency Injection BasicsMediumWrite Code
5/10
Depends()

Description

Create a FastAPI app that uses dependency injection for common parameters. Implement a `common_params` dependency that extracts pagination parameters (`skip` and `limit`) from query strings, and a `get_db` dependency that simulates a database session.

Requirements

01Create a `common_params` dependency function with `skip: int = 0` and `limit: int = 10`
02Create a `get_db` generator dependency that yields a mock DB session
03Use `Depends()` in your endpoint signature
04Return the items with pagination applied
Python 3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Ln 18, Col 1