]> git.ipfire.org Git - thirdparty/fastapi/fastapi.git/commitdiff
:memo: Update docs, async and features
authorSebastián Ramírez <tiangolo@gmail.com>
Thu, 13 Dec 2018 17:06:17 +0000 (21:06 +0400)
committerSebastián Ramírez <tiangolo@gmail.com>
Thu, 13 Dec 2018 17:06:17 +0000 (21:06 +0400)
docs/async.md
docs/features.md
docs/index.md

index f77fcafa4c26c73e13e52831f25b0c70cd9c1608..1c7bebf3a780ec7e93c33a9598caec07a8216628 100644 (file)
@@ -14,20 +14,21 @@ results = await some_library()
 
 Then, declare your endpoint functions with `async def` like:
 
-```Python
+```Python hl_lines="2"
 @app.get('/')
 async def read_results():
     results = await some_library()
     return results
 ```
 
-**Note**: You can only use `await` inside of functions created with `async def`.
+!!! note
+    You can only use `await` inside of functions created with `async def`.
 
 ---
 
 If you are using a third party library that communicates with something (a database, an API, the file system, etc) and doesn't have support for using `await`, (this is currently the case for most database libraries), then declare your endpoint functions as normally, with just `def`, like:
 
-```Python
+```Python hl_lines="2"
 @app.get('/')
 def results():
     results = some_library()
@@ -283,7 +284,7 @@ The key here is the `await`. It tells Python that it has to wait for `get_burger
 
 For `await` to work, it has to be inside a function that supports this asynchronicity. To do that, you just declare it with `async def`:
 
-```Python
+```Python hl_lines="1"
 async def get_burgers(number: int):
     # Do some asynchronous stuff to create the burgers
     return burgers
@@ -291,7 +292,7 @@ async def get_burgers(number: int):
 
 ...instead of `def`:
 
-```Python
+```Python hl_lines="2"
 # This is not asynchronous
 def get_sequential_burgers(number: int):
     # Do some sequential stuff to create the burgers
@@ -311,7 +312,7 @@ burgers = get_burgers(2)
 
 So, if you are using a library that tells you that you can call it with `await`, you need to create the endpoint that uses it with `async def`, like in:
 
-```Python
+```Python hl_lines="2 3"
 @app.get('/burgers')
 async def read_burgers():
     burgers = await get_burgers(2)
@@ -360,4 +361,4 @@ Let's see the same phrase from above:
 
 That should make more sense now.
 
-All that is what powers FastAPI (through Starlette) and what makes it so powerful and have an impressive performance.
+All that is what powers FastAPI (through Starlette) and what makes it have such an impressive performance.
index b35fa34b7bdefbee2a7eb9100b97e5b8bc376a2d..db76df5b22338e4bb32c640da05382705499f71c 100644 (file)
@@ -202,3 +202,4 @@ With **FastAPI** you get all of **Pydantic**'s features (as FastAPI is based on
     * You can have deeply **nested JSON** objects and have them all validated and annotated.
 * **Extendible**:
     * Pydantic allows custom data types to be defined or you can extend validation with methods on a model decorated with the validator decorator.
+* 100% test coverage.
\ No newline at end of file
index 6102bb21ea2fd17654f5409c87afb1d67fcc4e89..40df4afbe09cb0ba6dae7631ee9a94ac1572f58a 100644 (file)
@@ -27,12 +27,17 @@ FastAPI is a modern, fast (high-performance), web framework for building APIs wi
 The key features are:
 
 * **Fast**: Very high performance, on par with **NodeJS** and **Go** (thanks to Starlette and Pydantic).
+
+* **Fast to code**: Increase the speed to develop features by about 200% to 300% *.
+* **Less bugs**: Reduce about 40% of human (developer) induced errors. *
 * **Intuitive**: Great editor support. <abbr title="also known as auto-complete, autocompletion, IntelliSense">Completion</abbr> everywhere. Less time debugging.
 * **Easy**: Designed to be easy to use and learn. Less time reading docs.
-* **Short**: Minimize code duplication. Multiple features from each parameter declaration.
+* **Short**: Minimize code duplication. Multiple features from each parameter declaration. Less bugs.
 * **Robust**: Get production-ready code. With automatic interactive documentation.
 * **Standards-based**: Based on (and fully compatible with) the open standards for APIs: <a href="https://github.com/OAI/OpenAPI-Specification" target="_blank">OpenAPI</a> and <a href="http://json-schema.org/" target="_blank">JSON Schema</a>.
 
+<small>* estimation based on tests on an internal development team, building production applications.</small>
+
 
 ## Requirements
 
@@ -65,11 +70,27 @@ from fastapi import FastAPI
 
 app = FastAPI()
 
+@app.get('/')
+def read_root():
+    return {'hello': 'world'}
+```
+
+Or if your code uses `async` / `await`, use `async def`:
+
+```Python hl_lines="6"
+from fastapi import FastAPI
+
+app = FastAPI()
+
 @app.get('/')
 async def read_root():
     return {'hello': 'world'}
 ```
 
+!!! note
+    If you don't know, check the section about [`async` and `await` in the docs](async.md).
+
+
 * Run the server with:
 
 ```bash
@@ -118,7 +139,7 @@ Now modify the file `main.py` to include:
 * an optional query parameter `q`.
 
 
-```Python
+```Python hl_lines="2 7 8 9 10 19"
 from fastapi import FastAPI
 from pydantic import BaseModel
 
@@ -287,6 +308,9 @@ Used by Starlette:
 * <a href="https://graphene-python.org/" target="_blank"><code>graphene</code></a> - Required for `GraphQLApp` support.
 * <a href="https://github.com/esnme/ultrajson" target="_blank"><code>ujson</code></a> - Required if you want to use `UJSONResponse`.
 
+Used by FastAPI / Starlette:
+
+* <a href="http://www.uvicorn.org" target="_blank"><code>uvicorn</code></a> - for the server that loads and serves your application.
 
 You can install all of these with `pip3 install fastapi[full]`.