`APIRouter` class, used to group *path operations*, for example to structure an app in multiple files. It would then be included in the `FastAPI` app, or in another `APIRouter` (ultimately included in the app). Read more about it in the [FastAPI docs for Bigger Applications - M
| 2208 | |
| 2209 | |
| 2210 | class APIRouter(routing.Router): |
| 2211 | """ |
| 2212 | `APIRouter` class, used to group *path operations*, for example to structure |
| 2213 | an app in multiple files. It would then be included in the `FastAPI` app, or |
| 2214 | in another `APIRouter` (ultimately included in the app). |
| 2215 | |
| 2216 | Read more about it in the |
| 2217 | [FastAPI docs for Bigger Applications - Multiple Files](https://fastapi.tiangolo.com/tutorial/bigger-applications/). |
| 2218 | |
| 2219 | ## Example |
| 2220 | |
| 2221 | ```python |
| 2222 | from fastapi import APIRouter, FastAPI |
| 2223 | |
| 2224 | app = FastAPI() |
| 2225 | router = APIRouter() |
| 2226 | |
| 2227 | |
| 2228 | @router.get("/users/", tags=["users"]) |
| 2229 | async def read_users(): |
| 2230 | return [{"username": "Rick"}, {"username": "Morty"}] |
| 2231 | |
| 2232 | |
| 2233 | app.include_router(router) |
| 2234 | ``` |
| 2235 | """ |
| 2236 | |
| 2237 | def __init__( |
| 2238 | self, |
| 2239 | *, |
| 2240 | prefix: Annotated[str, Doc("An optional path prefix for the router.")] = "", |
| 2241 | tags: Annotated[ |
| 2242 | list[str | Enum] | None, |
| 2243 | Doc( |
| 2244 | """ |
| 2245 | A list of tags to be applied to all the *path operations* in this |
| 2246 | router. |
| 2247 | |
| 2248 | It will be added to the generated OpenAPI (e.g. visible at `/docs`). |
| 2249 | |
| 2250 | Read more about it in the |
| 2251 | [FastAPI docs for Path Operation Configuration](https://fastapi.tiangolo.com/tutorial/path-operation-configuration/). |
| 2252 | """ |
| 2253 | ), |
| 2254 | ] = None, |
| 2255 | dependencies: Annotated[ |
| 2256 | Sequence[params.Depends] | None, |
| 2257 | Doc( |
| 2258 | """ |
| 2259 | A list of dependencies (using `Depends()`) to be applied to all the |
| 2260 | *path operations* in this router. |
| 2261 | |
| 2262 | Read more about it in the |
| 2263 | [FastAPI docs for Bigger Applications - Multiple Files](https://fastapi.tiangolo.com/tutorial/bigger-applications/#include-an-apirouter-with-a-custom-prefix-tags-responses-and-dependencies). |
| 2264 | """ |
| 2265 | ), |
| 2266 | ] = None, |
| 2267 | default_response_class: Annotated[ |
no outgoing calls
searching dependent graphs…