]> git.ipfire.org Git - thirdparty/starlette.git/commitdiff
Match httpx documentation style (#2742)
authorMarcelo Trylesinski <marcelotryle@gmail.com>
Thu, 31 Oct 2024 07:05:06 +0000 (08:05 +0100)
committerGitHub <noreply@github.com>
Thu, 31 Oct 2024 07:05:06 +0000 (08:05 +0100)
docs/applications.md
docs/index.md
docs/release-notes.md
mkdocs.yml

index 6fb74f19f67b88a8c5a856ff726be1220432ec13..b90c20f3209354e11de191151cd989ffe1e8a687 100644 (file)
@@ -3,6 +3,8 @@ Starlette includes an application class `Starlette` that nicely ties together al
 its other functionality.
 
 ```python
+from contextlib import asynccontextmanager
+
 from starlette.applications import Starlette
 from starlette.responses import PlainTextResponse
 from starlette.routing import Route, Mount, WebSocketRoute
@@ -25,8 +27,11 @@ async def websocket_endpoint(websocket):
     await websocket.send_text('Hello, websocket!')
     await websocket.close()
 
-def startup():
-    print('Ready to go')
+@asyncontextmanager
+async def lifespan(app):
+    print('Startup')
+    yield
+    print('Shutdown')
 
 
 routes = [
@@ -37,7 +42,7 @@ routes = [
     Mount('/static', StaticFiles(directory="static")),
 ]
 
-app = Starlette(debug=True, routes=routes, on_startup=[startup])
+app = Starlette(debug=True, routes=routes, lifespan=lifespan)
 ```
 
 ### Instantiating the application
index cc243b43c637bd841e497125562ef52f1909d84d..faf1c7c55dde36d248c52b7bbae2b50821ce8c88 100644 (file)
@@ -1,7 +1,3 @@
----
-hide: navigation
----
-
 <p align="center">
   <img width="400px" src="/img/starlette.svg#only-light" alt="starlette"/>
   <img width="400px" src="/img/starlette_dark.svg#only-dark" alt="starlette"/>
@@ -52,18 +48,18 @@ It is production-ready, and gives you the following:
 ## Installation
 
 ```shell
-pip install starlette
+pip install starlette
 ```
 
 You'll also want to install an ASGI server, such as [uvicorn](https://www.uvicorn.org/), [daphne](https://github.com/django/daphne/), or [hypercorn](https://hypercorn.readthedocs.io/en/latest/).
 
 ```shell
-pip install uvicorn
+pip install uvicorn
 ```
 
 ## Example
 
-```python title="example.py"
+```python title="main.py"
 from starlette.applications import Starlette
 from starlette.responses import JSONResponse
 from starlette.routing import Route
@@ -81,11 +77,9 @@ app = Starlette(debug=True, routes=[
 Then run the application...
 
 ```shell
-$ uvicorn example:app
+uvicorn main:app
 ```
 
-For a more complete example, [see here](https://github.com/encode/starlette-example).
-
 ## Dependencies
 
 Starlette only requires `anyio`, and the following dependencies are optional:
@@ -103,7 +97,7 @@ You can install all of these with `pip install starlette[full]`.
 Starlette is designed to be used either as a complete framework, or as
 an ASGI toolkit. You can use any of its components independently.
 
-```python
+```python title="main.py"
 from starlette.responses import PlainTextResponse
 
 
@@ -113,10 +107,10 @@ async def app(scope, receive, send):
     await response(scope, receive, send)
 ```
 
-Run the `app` application in `example.py`:
+Run the `app` application in `main.py`:
 
 ```shell
-$ uvicorn example:app
+$ uvicorn main:app
 INFO: Started server process [11509]
 INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
 ```
index 1b56b342a3795ca3efbbcf8dae350d8271df2ae1..66186ebd27a26f2299471ce7a142375e33516e6b 100644 (file)
@@ -1,5 +1,4 @@
 ---
-hide: navigation
 toc_depth: 2
 ---
 
index ad503317ddc6a1d837aa21938c1ce6cafcd1bc1f..83d245e040006ba14e8357e250d361870eee04cb 100644 (file)
@@ -21,7 +21,6 @@ theme:
     repo: fontawesome/brands/github
   features:
     - content.code.copy
-    - navigation.tabs
     - toc.follow
 
 repo_name: encode/starlette
@@ -29,7 +28,7 @@ repo_url: https://github.com/encode/starlette
 edit_uri: edit/master/docs/
 
 nav:
-  - Home: "index.md"
+  - Introduction: "index.md"
   - Features:
       - Applications: "applications.md"
       - Requests: "requests.md"