Skip to content

Commit

Permalink
Match httpx documentation style (#2742)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex authored Oct 31, 2024
1 parent afeb7c2 commit c2e3a39
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
11 changes: 8 additions & 3 deletions docs/applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 = [
Expand All @@ -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
Expand Down
20 changes: 7 additions & 13 deletions docs/index.md
Original file line number Diff line number Diff line change
@@ -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"/>
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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


Expand All @@ -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)
```
Expand Down
1 change: 0 additions & 1 deletion docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
hide: navigation
toc_depth: 2
---

Expand Down
3 changes: 1 addition & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,14 @@ theme:
repo: fontawesome/brands/github
features:
- content.code.copy
- navigation.tabs
- toc.follow

repo_name: encode/starlette
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"
Expand Down

0 comments on commit c2e3a39

Please sign in to comment.