![]() ![]() We can also add path operations directly to the FastAPI app. So, for example, other projects could use the same APIRouter with a different authentication method. The result is that in our app, each of the path operations from the admin module will have:īut that will only affect that APIRouter in our app, not in any other code that uses it. And it has an empty file app/init.py, so it is a Python package (a collection of Python modules): app. That way, the original APIRouter will keep unmodified, so we can still share that same app/internal/admin.py file with other projects in the organization. dependencies import get_token_header router = APIRouter ( prefix = "/items", tags =, dependencies =, responses = You import it and create an "instance" the same way you would with the class FastAPI:įrom fastapi import APIRouter, Depends, HTTPException from. You can create the path operations for that module using APIRouter. You want to have the path operations related to your users separated from the rest of the code, to keep it organized.īut it's still part of the same FastAPI application/web API (it's part of the same "Python Package"). Let's say the file dedicated to handling just users is the submodule at /app/routers/users.py. │ ├── _init_.py # makes "internal" a "Python subpackage" │ └── internal # "internal" is a "Python subpackage" │ │ └── users.py # "users" submodule, e.g. │ │ ├── items.py # "items" submodule, e.g. │ │ ├── _init_.py # makes "routers" a "Python subpackage" │ └── routers # "routers" is a "Python subpackage" │ ├── dependencies.py # "dependencies" module, e.g. │ ├── _init_.py # this file makes "app" a "Python package" Include the same router multiple times with different prefix ![]() Include an APIRouter with a custom prefix, tags, responses, and dependencies The WebDAV protocol enables a webserver to behave like a fileserver too, supporting collaborative authoring of web content. Include the APIRouters for users and items WebDAV ( RFC 4918) is an extension to HTTP, the internet protocol that web-browsers and webservers use to communicate with each other. OAuth2 with Password (and hashing), Bearer with JWT tokensĪdd some custom tags, responses, and dependencies ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |