diff --git a/docs/tutorial/application-configuration.md b/docs/tutorial/application-configuration.md new file mode 100644 index 000000000..d9b970fc4 --- /dev/null +++ b/docs/tutorial/application-configuration.md @@ -0,0 +1,13 @@ +Coming soon... + +```Python +{!./tutorial/src/application-configuration/tutorial001.py!} +``` + +```Python +{!./tutorial/src/application-configuration/tutorial002.py!} +``` + +```Python +{!./tutorial/src/application-configuration/tutorial003.py!} +``` diff --git a/docs/tutorial/bigger-applications.md b/docs/tutorial/bigger-applications.md new file mode 100644 index 000000000..499acf685 --- /dev/null +++ b/docs/tutorial/bigger-applications.md @@ -0,0 +1,13 @@ +Coming soon... + +```Python +{!./tutorial/src/bigger-applications/tutorial001.py!} +``` + +```Python +{!./tutorial/src/bigger-applications/tutorial002.py!} +``` + +```Python +{!./tutorial/src/bigger-applications/tutorial003.py!} +``` diff --git a/docs/tutorial/dependencies/intro.md b/docs/tutorial/dependencies/intro.md index 3607cc0a5..73ccde672 100644 --- a/docs/tutorial/dependencies/intro.md +++ b/docs/tutorial/dependencies/intro.md @@ -51,7 +51,7 @@ You can define dependencies that in turn can define dependencies themselves. In the end, a hierarchical tree of dependencies is built, and the **Dependency Injection** system takes care of solving all these dependencies for you (and your dependencies) and providing the results at each step. -## Integrated with OpenAPI +## Integrated with **OpenAPI** All these dependencies, while declaring their requirements, might have been adding parameters, validations, etc. to your path operations. diff --git a/docs/tutorial/security/first-steps.md b/docs/tutorial/security/first-steps.md new file mode 100644 index 000000000..3cea5cb59 --- /dev/null +++ b/docs/tutorial/security/first-steps.md @@ -0,0 +1,5 @@ +Coming soon... + +```Python +{!./tutorial/src/security/tutorial002.py!} +``` diff --git a/docs/tutorial/security/intro.md b/docs/tutorial/security/intro.md new file mode 100644 index 000000000..e6891dad2 --- /dev/null +++ b/docs/tutorial/security/intro.md @@ -0,0 +1,5 @@ +Coming soon... + +```Python +{!./tutorial/src/security/tutorial001.py!} +``` diff --git a/docs/tutorial/security/oauth2-jwt.md b/docs/tutorial/security/oauth2-jwt.md new file mode 100644 index 000000000..7ceef9df2 --- /dev/null +++ b/docs/tutorial/security/oauth2-jwt.md @@ -0,0 +1,5 @@ +Coming soon... + +```Python +{!./tutorial/src/security/tutorial004.py!} +``` diff --git a/docs/tutorial/security/simple-oauth2.md b/docs/tutorial/security/simple-oauth2.md new file mode 100644 index 000000000..5dff95b11 --- /dev/null +++ b/docs/tutorial/security/simple-oauth2.md @@ -0,0 +1,5 @@ +Coming soon... + +```Python +{!./tutorial/src/security/tutorial003.py!} +``` diff --git a/docs/tutorial/src/all/tutorial001.py b/docs/tutorial/src/all/tutorial001.py deleted file mode 100644 index 183180cd7..000000000 --- a/docs/tutorial/src/all/tutorial001.py +++ /dev/null @@ -1,11 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items(q: str = Query(None, max_length=50)): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial002.py b/docs/tutorial/src/all/tutorial002.py deleted file mode 100644 index 311ece816..000000000 --- a/docs/tutorial/src/all/tutorial002.py +++ /dev/null @@ -1,11 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items(q: str = Query(None, min_length=3, max_length=50)): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial003.py b/docs/tutorial/src/all/tutorial003.py deleted file mode 100644 index 785db44c0..000000000 --- a/docs/tutorial/src/all/tutorial003.py +++ /dev/null @@ -1,13 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query(None, min_length=3, max_length=50, regex="^fixedquery$") -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial004.py b/docs/tutorial/src/all/tutorial004.py deleted file mode 100644 index 116829bef..000000000 --- a/docs/tutorial/src/all/tutorial004.py +++ /dev/null @@ -1,15 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query( - None, title="Query string", min_length=3, max_length=50, regex="^fixedquery$" - ) -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial005.py b/docs/tutorial/src/all/tutorial005.py deleted file mode 100644 index 67d5fd6a5..000000000 --- a/docs/tutorial/src/all/tutorial005.py +++ /dev/null @@ -1,20 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query( - None, - title="Query string", - description="Query string for the items to search in the database that have a good match", - min_length=3, - max_length=50, - regex="^fixedquery$", - ) -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial006.py b/docs/tutorial/src/all/tutorial006.py deleted file mode 100644 index a4e3b816c..000000000 --- a/docs/tutorial/src/all/tutorial006.py +++ /dev/null @@ -1,21 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query( - "fixedquery", - alias="item-query", - title="Query string", - description="Query string for the items to search in the database that have a good match", - min_length=3, - max_length=50, - regex="^fixedquery$", - ) -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial007.py b/docs/tutorial/src/all/tutorial007.py deleted file mode 100644 index f261c9554..000000000 --- a/docs/tutorial/src/all/tutorial007.py +++ /dev/null @@ -1,21 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query( - None, - alias="item-query", - title="Query string", - description="Query string for the items to search in the database that have a good match", - min_length=3, - max_length=50, - regex="^fixedquery$", - ) -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial008.py b/docs/tutorial/src/all/tutorial008.py deleted file mode 100644 index b9bffcaff..000000000 --- a/docs/tutorial/src/all/tutorial008.py +++ /dev/null @@ -1,21 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query( - ..., - alias="item-query", - title="Query string", - description="Query string for the items to search in the database that have a good match", - min_length=3, - max_length=50, - regex="^fixedquery$", - ) -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial009.py b/docs/tutorial/src/all/tutorial009.py deleted file mode 100644 index 051656c76..000000000 --- a/docs/tutorial/src/all/tutorial009.py +++ /dev/null @@ -1,22 +0,0 @@ -from fastapi import FastAPI, Query - -app = FastAPI() - - -@app.get("/items/") -async def read_items( - q: str = Query( - None, - alias="item-query", - title="Query string", - description="Query string for the items to search in the database that have a good match", - min_length=3, - max_length=50, - regex="^fixedquery$", - deprecated=True, - ) -): - results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial010.py b/docs/tutorial/src/all/tutorial010.py deleted file mode 100644 index fc1911872..000000000 --- a/docs/tutorial/src/all/tutorial010.py +++ /dev/null @@ -1,14 +0,0 @@ -from fastapi import FastAPI, Path, Query - -app = FastAPI() - - -@app.get("/items/{item_id}") -async def read_items( - item_id: int = Path(..., title="The ID of the item to get"), - q: str = Query(None, alias="item-query"), -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial011.py b/docs/tutorial/src/all/tutorial011.py deleted file mode 100644 index 57ca50ece..000000000 --- a/docs/tutorial/src/all/tutorial011.py +++ /dev/null @@ -1,13 +0,0 @@ -from fastapi import FastAPI, Path - -app = FastAPI() - - -@app.get("/items/{item_id}") -async def read_items( - q: str, item_id: int = Path(..., title="The ID of the item to get") -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial012.py b/docs/tutorial/src/all/tutorial012.py deleted file mode 100644 index b6b5a1986..000000000 --- a/docs/tutorial/src/all/tutorial012.py +++ /dev/null @@ -1,13 +0,0 @@ -from fastapi import FastAPI, Path - -app = FastAPI() - - -@app.get("/items/{item_id}") -async def read_items( - *, item_id: int = Path(..., title="The ID of the item to get"), q: str -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial013.py b/docs/tutorial/src/all/tutorial013.py deleted file mode 100644 index 2ec708280..000000000 --- a/docs/tutorial/src/all/tutorial013.py +++ /dev/null @@ -1,13 +0,0 @@ -from fastapi import FastAPI, Path - -app = FastAPI() - - -@app.get("/items/{item_id}") -async def read_items( - *, item_id: int = Path(..., title="The ID of the item to get", ge=1), q: str -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial014.py b/docs/tutorial/src/all/tutorial014.py deleted file mode 100644 index 2809f37b2..000000000 --- a/docs/tutorial/src/all/tutorial014.py +++ /dev/null @@ -1,15 +0,0 @@ -from fastapi import FastAPI, Path - -app = FastAPI() - - -@app.get("/items/{item_id}") -async def read_items( - *, - item_id: int = Path(..., title="The ID of the item to get", gt=0, le=1000), - q: str, -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial015.py b/docs/tutorial/src/all/tutorial015.py deleted file mode 100644 index 0c19579f5..000000000 --- a/docs/tutorial/src/all/tutorial015.py +++ /dev/null @@ -1,16 +0,0 @@ -from fastapi import FastAPI, Path, Query - -app = FastAPI() - - -@app.get("/items/{item_id}") -async def read_items( - *, - item_id: int = Path(..., title="The ID of the item to get", ge=0, le=1000), - q: str, - size: float = Query(..., gt=0, lt=10.5) -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial016.py b/docs/tutorial/src/all/tutorial016.py deleted file mode 100644 index 7918a2f96..000000000 --- a/docs/tutorial/src/all/tutorial016.py +++ /dev/null @@ -1,26 +0,0 @@ -from fastapi import FastAPI, Path -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - - -@app.put("/items/{item_id}") -async def update_item( - *, - item_id: int = Path(..., title="The ID of the item to get", ge=0, le=1000), - q: str, - item: Item = None, -): - results = {"item_id": item_id} - if q: - results.update({"q": q}) - if item: - results.update({"item": item}) - return results diff --git a/docs/tutorial/src/all/tutorial017.py b/docs/tutorial/src/all/tutorial017.py deleted file mode 100644 index 5c9e8344d..000000000 --- a/docs/tutorial/src/all/tutorial017.py +++ /dev/null @@ -1,22 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - - -class User(BaseModel): - username: str - full_name: str = None - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item, user: User): - results = {"item_id": item_id, "item": item, "user": user} - return results diff --git a/docs/tutorial/src/all/tutorial018.py b/docs/tutorial/src/all/tutorial018.py deleted file mode 100644 index 8dae852a5..000000000 --- a/docs/tutorial/src/all/tutorial018.py +++ /dev/null @@ -1,29 +0,0 @@ -from fastapi import Body, FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - - -class User(BaseModel): - username: str - full_name: str = None - - -@app.put("/items/{item_id}") -async def update_item( - *, item_id: int, item: Item, user: User, access_token: str = Body(...) -): - results = { - "item_id": item_id, - "item": item, - "user": user, - "access_token": access_token, - } - return results diff --git a/docs/tutorial/src/all/tutorial019.py b/docs/tutorial/src/all/tutorial019.py deleted file mode 100644 index 845618fdf..000000000 --- a/docs/tutorial/src/all/tutorial019.py +++ /dev/null @@ -1,36 +0,0 @@ -from fastapi import Body, FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - - -class User(BaseModel): - username: str - full_name: str = None - - -@app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item, - user: User, - access_token: str = Body(...), - q: str = None, -): - results = { - "item_id": item_id, - "item": item, - "user": user, - "access_token": access_token, - } - if q: - results.update({"q": q}) - return results diff --git a/docs/tutorial/src/all/tutorial020.py b/docs/tutorial/src/all/tutorial020.py deleted file mode 100644 index 61f1b2917..000000000 --- a/docs/tutorial/src/all/tutorial020.py +++ /dev/null @@ -1,17 +0,0 @@ -from fastapi import Body, FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item = Body(..., embed=True)): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial021.py b/docs/tutorial/src/all/tutorial021.py deleted file mode 100644 index 6c8b101ba..000000000 --- a/docs/tutorial/src/all/tutorial021.py +++ /dev/null @@ -1,17 +0,0 @@ -from fastapi import Body, FastAPI -from pydantic import BaseModel, Schema - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = Schema(None, title="The description of the item", max_length=300) - price: float = Schema(..., gt=0, description="The price must be greater than zero") - tax: float = None - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item = Body(..., embed=True)): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial022.py b/docs/tutorial/src/all/tutorial022.py deleted file mode 100644 index 1165fd7a0..000000000 --- a/docs/tutorial/src/all/tutorial022.py +++ /dev/null @@ -1,29 +0,0 @@ -from fastapi import Body, FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - - -@app.put("/items/{item_id}") -async def update_item( - *, - item_id: int, - item: Item = Body( - ..., - example={ - "name": "Foo", - "description": "A very nice Item", - "price": 35.4, - "tax": 3.2, - }, - ) -): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial023.py b/docs/tutorial/src/all/tutorial023.py deleted file mode 100644 index 9e0fa4494..000000000 --- a/docs/tutorial/src/all/tutorial023.py +++ /dev/null @@ -1,18 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: list = [] - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial024.py b/docs/tutorial/src/all/tutorial024.py deleted file mode 100644 index 8f769279b..000000000 --- a/docs/tutorial/src/all/tutorial024.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import List - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: List[str] = [] - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial025.py b/docs/tutorial/src/all/tutorial025.py deleted file mode 100644 index 291b3c64d..000000000 --- a/docs/tutorial/src/all/tutorial025.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial026.py b/docs/tutorial/src/all/tutorial026.py deleted file mode 100644 index 257928ef3..000000000 --- a/docs/tutorial/src/all/tutorial026.py +++ /dev/null @@ -1,26 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Image(BaseModel): - url: str - name: str - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - image: Image = None - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial027.py b/docs/tutorial/src/all/tutorial027.py deleted file mode 100644 index f5f19b390..000000000 --- a/docs/tutorial/src/all/tutorial027.py +++ /dev/null @@ -1,27 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import UrlStr - -app = FastAPI() - - -class Image(BaseModel): - url: UrlStr - name: str - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - image: Image = None - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial028.py b/docs/tutorial/src/all/tutorial028.py deleted file mode 100644 index 09d8be768..000000000 --- a/docs/tutorial/src/all/tutorial028.py +++ /dev/null @@ -1,27 +0,0 @@ -from typing import List, Set - -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import UrlStr - -app = FastAPI() - - -class Image(BaseModel): - url: UrlStr - name: str - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - image: List[Image] = None - - -@app.put("/items/{item_id}") -async def update_item(*, item_id: int, item: Item): - results = {"item_id": item_id, "item": item} - return results diff --git a/docs/tutorial/src/all/tutorial029.py b/docs/tutorial/src/all/tutorial029.py deleted file mode 100644 index cda802d3e..000000000 --- a/docs/tutorial/src/all/tutorial029.py +++ /dev/null @@ -1,33 +0,0 @@ -from typing import List, Set - -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import UrlStr - -app = FastAPI() - - -class Image(BaseModel): - url: UrlStr - name: str - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - image: List[Image] = None - - -class Offer(BaseModel): - name: str - description: str = None - price: float - items: List[Item] - - -@app.post("/offers/") -async def create_offer(*, offer: Offer): - return offer diff --git a/docs/tutorial/src/all/tutorial030.py b/docs/tutorial/src/all/tutorial030.py deleted file mode 100644 index 34b868563..000000000 --- a/docs/tutorial/src/all/tutorial030.py +++ /dev/null @@ -1,17 +0,0 @@ -from typing import List - -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import UrlStr - -app = FastAPI() - - -class Image(BaseModel): - url: UrlStr - name: str - - -@app.post("/images/multiple/") -async def create_multiple_images(*, images: List[Image]): - return images diff --git a/docs/tutorial/src/all/tutorial031.py b/docs/tutorial/src/all/tutorial031.py deleted file mode 100644 index 5a6fd30fe..000000000 --- a/docs/tutorial/src/all/tutorial031.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import Cookie, FastAPI - -app = FastAPI() - - -@app.get("/items/") -async def read_items(*, ads_id: str = Cookie(None)): - return {"ads_id": ads_id} diff --git a/docs/tutorial/src/all/tutorial032.py b/docs/tutorial/src/all/tutorial032.py deleted file mode 100644 index 24a59e530..000000000 --- a/docs/tutorial/src/all/tutorial032.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI, Header - -app = FastAPI() - - -@app.get("/items/") -async def read_items(*, accept_encoding: str = Header(None)): - return {"Accept-Encoding": accept_encoding} diff --git a/docs/tutorial/src/all/tutorial033.py b/docs/tutorial/src/all/tutorial033.py deleted file mode 100644 index 4edc4b6fd..000000000 --- a/docs/tutorial/src/all/tutorial033.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI, Header - -app = FastAPI() - - -@app.get("/items/") -async def read_items(*, strange_header: str = Header(None, convert_underscores=False)): - return {"strange_header": strange_header} diff --git a/docs/tutorial/src/all/tutorial034.py b/docs/tutorial/src/all/tutorial034.py deleted file mode 100644 index 86dadcbda..000000000 --- a/docs/tutorial/src/all/tutorial034.py +++ /dev/null @@ -1,19 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.post("/items/", response_model=Item) -async def create_item(*, item: Item): - return item diff --git a/docs/tutorial/src/all/tutorial035.py b/docs/tutorial/src/all/tutorial035.py deleted file mode 100644 index 3fb475b9d..000000000 --- a/docs/tutorial/src/all/tutorial035.py +++ /dev/null @@ -1,18 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import EmailStr - -app = FastAPI() - - -class UserIn(BaseModel): - username: str - password: str - email: EmailStr - full_name: str = None - - -# Don't do this in production! -@app.post("/user/", response_model=UserIn) -async def create_user(*, user: UserIn): - return user diff --git a/docs/tutorial/src/all/tutorial036.py b/docs/tutorial/src/all/tutorial036.py deleted file mode 100644 index c8ea361d8..000000000 --- a/docs/tutorial/src/all/tutorial036.py +++ /dev/null @@ -1,23 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import EmailStr - -app = FastAPI() - - -class UserIn(BaseModel): - username: str - password: str - email: EmailStr - full_name: str = None - - -class UserOut(BaseModel): - username: str - email: EmailStr - full_name: str = None - - -@app.post("/user/", response_model=UserOut) -async def create_user(*, user: UserIn): - return user diff --git a/docs/tutorial/src/all/tutorial037.py b/docs/tutorial/src/all/tutorial037.py deleted file mode 100644 index aa8e7dad4..000000000 --- a/docs/tutorial/src/all/tutorial037.py +++ /dev/null @@ -1,42 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import EmailStr - -app = FastAPI() - - -class UserIn(BaseModel): - username: str - password: str - email: EmailStr - full_name: str = None - - -class UserOut(BaseModel): - username: str - email: EmailStr - full_name: str = None - - -class UserInDB(BaseModel): - username: str - hashed_password: str - email: EmailStr - full_name: str = None - - -def fake_password_hasher(raw_password: str): - return "supersecret" + raw_password - - -def fake_save_user(user_in: UserIn): - hashed_password = fake_password_hasher(user_in.password) - user_in_db = UserInDB(**user_in.dict(), hashed_password=hashed_password) - print("User saved! ..not really") - return user_in_db - - -@app.post("/user/", response_model=UserOut) -async def create_user(*, user_in: UserIn): - user_saved = fake_save_user(user_in) - return user_saved diff --git a/docs/tutorial/src/all/tutorial038.py b/docs/tutorial/src/all/tutorial038.py deleted file mode 100644 index 605baf91f..000000000 --- a/docs/tutorial/src/all/tutorial038.py +++ /dev/null @@ -1,40 +0,0 @@ -from fastapi import FastAPI -from pydantic import BaseModel -from pydantic.types import EmailStr - -app = FastAPI() - - -class UserBase(BaseModel): - username: str - email: EmailStr - full_name: str = None - - -class UserIn(UserBase): - password: str - - -class UserOut(UserBase): - pass - - -class UserInDB(UserBase): - hashed_password: str - - -def fake_password_hasher(raw_password: str): - return "supersecret" + raw_password - - -def fake_save_user(user_in: UserIn): - hashed_password = fake_password_hasher(user_in.password) - user_in_db = UserInDB(**user_in.dict(), hashed_password=hashed_password) - print("User saved! ..not really") - return user_in_db - - -@app.post("/user/", response_model=UserOut) -async def create_user(*, user_in: UserIn): - user_saved = fake_save_user(user_in) - return user_saved diff --git a/docs/tutorial/src/all/tutorial039.py b/docs/tutorial/src/all/tutorial039.py deleted file mode 100644 index 0290b644d..000000000 --- a/docs/tutorial/src/all/tutorial039.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI, Form - -app = FastAPI() - - -@app.post("/login/") -async def login(*, username: str = Form(...), password: str = Form(...)): - return {"username": username} diff --git a/docs/tutorial/src/all/tutorial040.py b/docs/tutorial/src/all/tutorial040.py deleted file mode 100644 index 3e99fcdde..000000000 --- a/docs/tutorial/src/all/tutorial040.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI, File - -app = FastAPI() - - -@app.post("/files/") -async def create_file(*, file: bytes = File(...)): - return {"file_size": len(file)} diff --git a/docs/tutorial/src/all/tutorial041.py b/docs/tutorial/src/all/tutorial041.py deleted file mode 100644 index 1882a6397..000000000 --- a/docs/tutorial/src/all/tutorial041.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI, File, Form - -app = FastAPI() - - -@app.post("/files/") -async def create_file(*, file: bytes = File(...), token: str = Form(...)): - return {"file_size": len(file), "token": token} diff --git a/docs/tutorial/src/all/tutorial042.py b/docs/tutorial/src/all/tutorial042.py deleted file mode 100644 index b48601867..000000000 --- a/docs/tutorial/src/all/tutorial042.py +++ /dev/null @@ -1,20 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel -from starlette.status import HTTP_201_CREATED - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.post("/items/", response_model=Item, status_code=HTTP_201_CREATED) -async def create_item(*, item: Item): - return item diff --git a/docs/tutorial/src/all/tutorial043.py b/docs/tutorial/src/all/tutorial043.py deleted file mode 100644 index ccd5437da..000000000 --- a/docs/tutorial/src/all/tutorial043.py +++ /dev/null @@ -1,19 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.post("/items/", response_model=Item, tags=["items"]) -async def create_item(*, item: Item): - return item diff --git a/docs/tutorial/src/all/tutorial044.py b/docs/tutorial/src/all/tutorial044.py deleted file mode 100644 index 106607fd2..000000000 --- a/docs/tutorial/src/all/tutorial044.py +++ /dev/null @@ -1,24 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.post( - "/items/", - response_model=Item, - summary="Create an item", - description="Create an item with all the information, name, description, price, tax and a set of unique tags", -) -async def create_item(*, item: Item): - return item diff --git a/docs/tutorial/src/all/tutorial045.py b/docs/tutorial/src/all/tutorial045.py deleted file mode 100644 index a4151a8cd..000000000 --- a/docs/tutorial/src/all/tutorial045.py +++ /dev/null @@ -1,28 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.post("/items/", response_model=Item, summary="Create an item") -async def create_item(*, item: Item): - """ - Create an item with all the information: - - * name: each item must have a name - * description: a long description - * price: required - * tax: if the item doesn't have tax, you can omit this - * tags: a set of unique tag strings for this item - """ - return item diff --git a/docs/tutorial/src/all/tutorial046.py b/docs/tutorial/src/all/tutorial046.py deleted file mode 100644 index f710e6c66..000000000 --- a/docs/tutorial/src/all/tutorial046.py +++ /dev/null @@ -1,33 +0,0 @@ -from typing import Set - -from fastapi import FastAPI -from pydantic import BaseModel - -app = FastAPI() - - -class Item(BaseModel): - name: str - description: str = None - price: float - tax: float = None - tags: Set[str] = [] - - -@app.post( - "/items/", - response_model=Item, - summary="Create an item", - response_description="The created item", -) -async def create_item(*, item: Item): - """ - Create an item with all the information: - - * name: each item must have a name - * description: a long description - * price: required - * tax: if the item doesn't have tax, you can omit this - * tags: a set of unique tag strings for this item - """ - return item diff --git a/docs/tutorial/src/all/tutorial047.py b/docs/tutorial/src/all/tutorial047.py deleted file mode 100644 index 11f3de6db..000000000 --- a/docs/tutorial/src/all/tutorial047.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI - -app = FastAPI() - - -@app.get("/items/", deprecated=True) -async def read_items(): - return [{"item_id": "Foo"}] diff --git a/docs/tutorial/src/all/tutorial048.py b/docs/tutorial/src/all/tutorial048.py deleted file mode 100644 index fafa8ffb8..000000000 --- a/docs/tutorial/src/all/tutorial048.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI - -app = FastAPI() - - -@app.get("/items/", operation_id="some_specific_id_you_define") -async def read_items(): - return [{"item_id": "Foo"}] diff --git a/docs/tutorial/src/all/tutorial049.py b/docs/tutorial/src/all/tutorial049.py deleted file mode 100644 index dcc358e32..000000000 --- a/docs/tutorial/src/all/tutorial049.py +++ /dev/null @@ -1,8 +0,0 @@ -from fastapi import FastAPI - -app = FastAPI() - - -@app.get("/items/", include_in_schema=False) -async def read_items(): - return [{"item_id": "Foo"}] diff --git a/docs/tutorial/src/all/tutorial050.py b/docs/tutorial/src/all/tutorial050.py deleted file mode 100644 index bba3f342d..000000000 --- a/docs/tutorial/src/all/tutorial050.py +++ /dev/null @@ -1,9 +0,0 @@ -from fastapi import FastAPI -from starlette.responses import UJSONResponse - -app = FastAPI() - - -@app.get("/items/", content_type=UJSONResponse) -async def read_items(): - return [{"item_id": "Foo"}] diff --git a/docs/tutorial/src/all/tutorial051.py b/docs/tutorial/src/all/tutorial051.py deleted file mode 100644 index 214e64263..000000000 --- a/docs/tutorial/src/all/tutorial051.py +++ /dev/null @@ -1,18 +0,0 @@ -from fastapi import FastAPI -from starlette.responses import HTMLResponse - -app = FastAPI() - - -@app.get("/items/", content_type=HTMLResponse) -async def read_items(): - return """ - -
-