Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 8 additions & 24 deletions docs/vi/docs/tutorial/first-steps.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

Tệp tin FastAPI đơn giản nhất có thể trông như này:

```Python
{!../../docs_src/first_steps/tutorial001.py!}
```
{* ../../docs_src/first_steps/tutorial001.py *}

Sao chép sang một tệp tin `main.py`.

Expand Down Expand Up @@ -133,9 +131,7 @@ Bạn cũng có thể sử dụng nó để sinh code tự động, với các c

### Bước 1: import `FastAPI`

```Python hl_lines="1"
{!../../docs_src/first_steps/tutorial001.py!}
```
{* ../../docs_src/first_steps/tutorial001.py hl[1] *}

`FastAPI` là một Python class cung cấp tất cả chức năng cho API của bạn.

Expand All @@ -149,9 +145,7 @@ Bạn cũng có thể sử dụng tất cả <a href="https://www.starlette.io/"

### Bước 2: Tạo một `FastAPI` "instance"

```Python hl_lines="3"
{!../../docs_src/first_steps/tutorial001.py!}
```
{* ../../docs_src/first_steps/tutorial001.py hl[3] *}

Biến `app` này là một "instance" của class `FastAPI`.

Expand All @@ -171,9 +165,7 @@ $ uvicorn main:app --reload

Nếu bạn tạo ứng dụng của bạn giống như:

```Python hl_lines="3"
{!../../docs_src/first_steps/tutorial002.py!}
```
{* ../../docs_src/first_steps/tutorial002.py hl[3] *}

Và đặt nó trong một tệp tin `main.py`, sau đó bạn sẽ gọi `uvicorn` giống như:

Expand Down Expand Up @@ -250,9 +242,7 @@ Chúng ta cũng sẽ gọi chúng là "**các toán tử**".

#### Định nghĩa moojt *decorator cho đường dẫn toán tử*

```Python hl_lines="6"
{!../../docs_src/first_steps/tutorial001.py!}
```
{* ../../docs_src/first_steps/tutorial001.py hl[6] *}

`@app.get("/")` nói **FastAPI** rằng hàm bên dưới có trách nhiệm xử lí request tới:

Expand Down Expand Up @@ -306,9 +296,7 @@ Ví dụ, khi sử dụng GraphQL bạn thông thường thực hiện tất c
* **toán tử**: là `get`.
* **hàm**: là hàm bên dưới "decorator" (bên dưới `@app.get("/")`).

```Python hl_lines="7"
{!../../docs_src/first_steps/tutorial001.py!}
```
{* ../../docs_src/first_steps/tutorial001.py hl[7] *}

Đây là một hàm Python.

Expand All @@ -320,9 +308,7 @@ Trong trường hợp này, nó là một hàm `async`.

Bạn cũng có thể định nghĩa nó như là một hàm thông thường thay cho `async def`:

```Python hl_lines="7"
{!../../docs_src/first_steps/tutorial003.py!}
```
{* ../../docs_src/first_steps/tutorial003.py hl[7] *}

/// note

Expand All @@ -332,9 +318,7 @@ Nếu bạn không biết sự khác nhau, kiểm tra [Async: *"Trong khi vội

### Bước 5: Nội dung trả về

```Python hl_lines="8"
{!../../docs_src/first_steps/tutorial001.py!}
```
{* ../../docs_src/first_steps/tutorial001.py hl[8] *}

Bạn có thể trả về một `dict`, `list`, một trong những giá trị đơn như `str`, `int`,...

Expand Down