Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'tiangolo:master' into de/docs/tutorial/response-model.md
- Loading branch information
Showing
61 changed files
with
11,825 additions
and
1,010 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# About | ||
|
||
About FastAPI, its design, inspiration and more. 🤓 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
--- | ||
hide: | ||
- navigation | ||
--- | ||
|
||
# Features | ||
|
||
## FastAPI features | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Help | ||
|
||
Help and get help, contribute, get involved. 🤝 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Learn | ||
|
||
Here are the introductory sections and the tutorials to learn **FastAPI**. | ||
|
||
You could consider this a **book**, a **course**, the **official** and recommended way to learn FastAPI. 😎 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# `APIRouter` class | ||
|
||
Here's the reference information for the `APIRouter` class, with all its parameters, | ||
attributes and methods. | ||
|
||
You can import the `APIRouter` class directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import APIRouter | ||
``` | ||
|
||
::: fastapi.APIRouter | ||
options: | ||
members: | ||
- websocket | ||
- include_router | ||
- get | ||
- put | ||
- post | ||
- delete | ||
- options | ||
- head | ||
- patch | ||
- trace | ||
- on_event |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Background Tasks - `BackgroundTasks` | ||
|
||
You can declare a parameter in a *path operation function* or dependency function | ||
with the type `BackgroundTasks`, and then you can use it to schedule the execution | ||
of background tasks after the response is sent. | ||
|
||
You can import it directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import BackgroundTasks | ||
``` | ||
|
||
::: fastapi.BackgroundTasks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Dependencies - `Depends()` and `Security()` | ||
|
||
## `Depends()` | ||
|
||
Dependencies are handled mainly with the special function `Depends()` that takes a | ||
callable. | ||
|
||
Here is the reference for it and its parameters. | ||
|
||
You can import it directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import Depends | ||
``` | ||
|
||
::: fastapi.Depends | ||
|
||
## `Security()` | ||
|
||
For many scenarios, you can handle security (authorization, authentication, etc.) with | ||
dependendencies, using `Depends()`. | ||
|
||
But when you want to also declare OAuth2 scopes, you can use `Security()` instead of | ||
`Depends()`. | ||
|
||
You can import `Security()` directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import Security | ||
``` | ||
|
||
::: fastapi.Security |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Encoders - `jsonable_encoder` | ||
|
||
::: fastapi.encoders.jsonable_encoder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Exceptions - `HTTPException` and `WebSocketException` | ||
|
||
These are the exceptions that you can raise to show errors to the client. | ||
|
||
When you raise an exception, as would happen with normal Python, the rest of the | ||
excecution is aborted. This way you can raise these exceptions from anywhere in the | ||
code to abort a request and show the error to the client. | ||
|
||
You can use: | ||
|
||
* `HTTPException` | ||
* `WebSocketException` | ||
|
||
These exceptions can be imported directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import HTTPException, WebSocketException | ||
``` | ||
|
||
::: fastapi.HTTPException | ||
|
||
::: fastapi.WebSocketException |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# `FastAPI` class | ||
|
||
Here's the reference information for the `FastAPI` class, with all its parameters, | ||
attributes and methods. | ||
|
||
You can import the `FastAPI` class directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import FastAPI | ||
``` | ||
|
||
::: fastapi.FastAPI | ||
options: | ||
members: | ||
- openapi_version | ||
- webhooks | ||
- state | ||
- dependency_overrides | ||
- openapi | ||
- websocket | ||
- include_router | ||
- get | ||
- put | ||
- post | ||
- delete | ||
- options | ||
- head | ||
- patch | ||
- trace | ||
- on_event | ||
- middleware | ||
- exception_handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# `HTTPConnection` class | ||
|
||
When you want to define dependencies that should be compatible with both HTTP and | ||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a | ||
`Request` or a `WebSocket`. | ||
|
||
You can import it from `fastapi.requests`: | ||
|
||
```python | ||
from fastapi.requests import HTTPConnection | ||
``` | ||
|
||
::: fastapi.requests.HTTPConnection |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Reference - Code API | ||
|
||
Here's the reference or code API, the classes, functions, parameters, attributes, and | ||
all the FastAPI parts you can use in you applications. | ||
|
||
If you want to **learn FastAPI** you are much better off reading the | ||
[FastAPI Tutorial](https://fastapi.tiangolo.com/tutorial/). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# Middleware | ||
|
||
There are several middlewares available provided by Starlette directly. | ||
|
||
Read more about them in the | ||
[FastAPI docs for Middleware](https://fastapi.tiangolo.com/advanced/middleware/). | ||
|
||
::: fastapi.middleware.cors.CORSMiddleware | ||
|
||
It can be imported from `fastapi`: | ||
|
||
```python | ||
from fastapi.middleware.cors import CORSMiddleware | ||
``` | ||
|
||
::: fastapi.middleware.gzip.GZipMiddleware | ||
|
||
It can be imported from `fastapi`: | ||
|
||
```python | ||
from fastapi.middleware.gzip import GZipMiddleware | ||
``` | ||
|
||
::: fastapi.middleware.httpsredirect.HTTPSRedirectMiddleware | ||
|
||
It can be imported from `fastapi`: | ||
|
||
```python | ||
from fastapi.middleware.httpsredirect import HTTPSRedirectMiddleware | ||
``` | ||
|
||
::: fastapi.middleware.trustedhost.TrustedHostMiddleware | ||
|
||
It can be imported from `fastapi`: | ||
|
||
```python | ||
from fastapi.middleware.trustedhost import TrustedHostMiddleware | ||
``` | ||
|
||
::: fastapi.middleware.wsgi.WSGIMiddleware | ||
|
||
It can be imported from `fastapi`: | ||
|
||
```python | ||
from fastapi.middleware.wsgi import WSGIMiddleware | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# OpenAPI `docs` | ||
|
||
Utilities to handle OpenAPI automatic UI documentation, including Swagger UI (by default at `/docs`) and ReDoc (by default at `/redoc`). | ||
|
||
::: fastapi.openapi.docs.get_swagger_ui_html | ||
|
||
::: fastapi.openapi.docs.get_redoc_html | ||
|
||
::: fastapi.openapi.docs.get_swagger_ui_oauth2_redirect_html | ||
|
||
::: fastapi.openapi.docs.swagger_ui_default_parameters |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# OpenAPI | ||
|
||
There are several utilities to handle OpenAPI. | ||
|
||
You normally don't need to use them unless you have a specific advanced use case that requires it. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# OpenAPI `models` | ||
|
||
OpenAPI Pydantic models used to generate and validate the generated OpenAPI. | ||
|
||
::: fastapi.openapi.models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Request Parameters | ||
|
||
Here's the reference information for the request parameters. | ||
|
||
These are the special functions that you can put in *path operation function* | ||
parameters or dependency functions with `Annotated` to get data from the request. | ||
|
||
It includes: | ||
|
||
* `Query()` | ||
* `Path()` | ||
* `Body()` | ||
* `Cookie()` | ||
* `Header()` | ||
* `Form()` | ||
* `File()` | ||
|
||
You can import them all directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import Body, Cookie, File, Form, Header, Path, Query | ||
``` | ||
|
||
::: fastapi.Query | ||
|
||
::: fastapi.Path | ||
|
||
::: fastapi.Body | ||
|
||
::: fastapi.Cookie | ||
|
||
::: fastapi.Header | ||
|
||
::: fastapi.Form | ||
|
||
::: fastapi.File |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# `Request` class | ||
|
||
You can declare a parameter in a *path operation function* or dependency to be of type | ||
`Request` and then you can access the raw request object directly, without any | ||
validation, etc. | ||
|
||
You can import it directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import Request | ||
``` | ||
|
||
!!! tip | ||
When you want to define dependencies that should be compatible with both HTTP and | ||
WebSockets, you can define a parameter that takes an `HTTPConnection` instead of a | ||
`Request` or a `WebSocket`. | ||
|
||
::: fastapi.Request |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# `Response` class | ||
|
||
You can declare a parameter in a *path operation function* or dependency to be of type | ||
`Response` and then you can set data for the response like headers or cookies. | ||
|
||
You can also use it directly to create an instance of it and return it from your *path | ||
operations*. | ||
|
||
You can import it directly from `fastapi`: | ||
|
||
```python | ||
from fastapi import Response | ||
``` | ||
|
||
::: fastapi.Response |
Oops, something went wrong.