mirror of https://github.com/tiangolo/fastapi.git
📝 Update includes in `docs/en/docs/tutorial/first-steps.md` (#12552)
This commit is contained in:
parent
71fcafd13c
commit
56bc9a5eb4
|
|
@ -2,9 +2,7 @@
|
|||
|
||||
The simplest FastAPI file could look like this:
|
||||
|
||||
```Python
|
||||
{!../../docs_src/first_steps/tutorial001.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial001.py *}
|
||||
|
||||
Copy that to a file `main.py`.
|
||||
|
||||
|
|
@ -157,9 +155,7 @@ You could also use it to generate code automatically, for clients that communica
|
|||
|
||||
### Step 1: import `FastAPI`
|
||||
|
||||
```Python hl_lines="1"
|
||||
{!../../docs_src/first_steps/tutorial001.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial001.py hl[1] *}
|
||||
|
||||
`FastAPI` is a Python class that provides all the functionality for your API.
|
||||
|
||||
|
|
@ -173,9 +169,7 @@ You can use all the <a href="https://www.starlette.io/" class="external-link" ta
|
|||
|
||||
### Step 2: create a `FastAPI` "instance"
|
||||
|
||||
```Python hl_lines="3"
|
||||
{!../../docs_src/first_steps/tutorial001.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial001.py hl[3] *}
|
||||
|
||||
Here the `app` variable will be an "instance" of the class `FastAPI`.
|
||||
|
||||
|
|
@ -244,9 +238,7 @@ We are going to call them "**operations**" too.
|
|||
|
||||
#### Define a *path operation decorator*
|
||||
|
||||
```Python hl_lines="6"
|
||||
{!../../docs_src/first_steps/tutorial001.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial001.py hl[6] *}
|
||||
|
||||
The `@app.get("/")` tells **FastAPI** that the function right below is in charge of handling requests that go to:
|
||||
|
||||
|
|
@ -300,9 +292,7 @@ This is our "**path operation function**":
|
|||
* **operation**: is `get`.
|
||||
* **function**: is the function below the "decorator" (below `@app.get("/")`).
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!../../docs_src/first_steps/tutorial001.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial001.py hl[7] *}
|
||||
|
||||
This is a Python function.
|
||||
|
||||
|
|
@ -314,9 +304,7 @@ In this case, it is an `async` function.
|
|||
|
||||
You could also define it as a normal function instead of `async def`:
|
||||
|
||||
```Python hl_lines="7"
|
||||
{!../../docs_src/first_steps/tutorial003.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial003.py hl[7] *}
|
||||
|
||||
/// note
|
||||
|
||||
|
|
@ -326,9 +314,7 @@ If you don't know the difference, check the [Async: *"In a hurry?"*](../async.md
|
|||
|
||||
### Step 5: return the content
|
||||
|
||||
```Python hl_lines="8"
|
||||
{!../../docs_src/first_steps/tutorial001.py!}
|
||||
```
|
||||
{* ../../docs_src/first_steps/tutorial001.py hl[8] *}
|
||||
|
||||
You can return a `dict`, `list`, singular values as `str`, `int`, etc.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue