Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomchristie committed Aug 29, 2018
1 parent 25990db commit 352ccda
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 9 deletions.
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
www.starlette.io
20 changes: 18 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ Python 3.6+
## Installation

```shell
pip3 install starlette
$ pip3 install starlette
```

## Example

```python
from starlette import Response
from starlette.response import Response


class App:
Expand All @@ -53,5 +53,21 @@ class App:

You can run the application with any ASGI server, including [uvicorn](http://www.uvicorn.org/), [daphne](https://github.com/django/daphne/), or [hypercorn](https://pgjones.gitlab.io/hypercorn/).

Install the Uvicorn ASGI server:

```shell
$ pip3 install uvicorn
[...]
Successfully installed uvicorn
```

Run the `App` application in `example.py`:

```shell
$ uvicorn run example:App
INFO: Started server process [11509]
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
```

<p align="center">&mdash; ⭐️ &mdash;</p>
<p align="center"><i>Starlette is <a href="https://github.com/tomchristie/starlette/blob/master/LICENSE.md">BSD licensed</a> code. Designed & built in Brighton, England.</i></p>
8 changes: 8 additions & 0 deletions docs/requests.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ the incoming request, rather than accessing the ASGI scope and receive channel d
Signature: `Request(scope, receive=None)`

```python
from starlette.request import Request
from starlette.response import Response


class App:
def __init__(self, scope):
self.scope = scope
Expand Down Expand Up @@ -62,6 +66,10 @@ The request body, parsed as JSON: `await request.json()`
You can also access the request body as a stream, using the `async for` syntax:

```python
from starlette.request import Request
from starlette.response import Response


class App:
def __init__(self, scope):
self.scope = scope
Expand Down
15 changes: 9 additions & 6 deletions docs/responses.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Once you've instantiated a response, you can send it by calling it as an
ASGI application instance.

```python
from starlette.response import Response


class App:
def __init__(self, scope):
self.scope = scope
Expand All @@ -33,7 +36,7 @@ class App:
Takes some text or bytes and returns an HTML response.

```python
from starlette import HTMLResponse
from starlette.response import HTMLResponse


class App:
Expand All @@ -50,7 +53,7 @@ class App:
Takes some text or bytes and returns an plain text response.

```python
from starlette import PlainTextResponse
from starlette.response import PlainTextResponse


class App:
Expand All @@ -67,7 +70,7 @@ class App:
Takes some data and returns an `application/json` encoded response.

```python
from starlette import JSONResponse
from starlette.response import JSONResponse


class App:
Expand All @@ -84,7 +87,7 @@ class App:
Returns an HTTP redirect. Uses a 302 status code by default.

```python
from starlette import PlainTextResponse, RedirectResponse
from starlette.response import PlainTextResponse, RedirectResponse


class App:
Expand All @@ -104,7 +107,7 @@ class App:
Takes an async generator and streams the response body.

```python
from starlette import Request, StreamingResponse
from starlette.response import StreamingResponse
import asyncio


Expand Down Expand Up @@ -140,7 +143,7 @@ Takes a different set of arguments to instantiate than the other response types:
File responses will include appropriate `Content-Length`, `Last-Modified` and `ETag` headers.

```python
from starlette import FileResponse
from starlette.response import FileResponse


class App:
Expand Down
2 changes: 1 addition & 1 deletion docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You can also route based on the incoming protocol, using the `ProtocolRouter`
class.

```python
from starlette.responses import Response
from starlette.response import Response
from starlette.routing import ProtocolRouter
from starlette.websockets import WebSocketSession

Expand Down
23 changes: 23 additions & 0 deletions docs/staticfiles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

As well as the `FileResponse` class, Starlette also includes ASGI applications
for serving a specific file or directory:

* `StaticFile(path)` - Serve a single file, given by `path`.
* `StaticFiles(directory)` - Serve any files in the given `directory`.

You can combine these ASGI applications with Starlette's routing to provide
comprehensive static file serving.

```python
from starlette.routing import Router, Path, PathPrefix
from starlette.staticfiles import StaticFile, StaticFiles


app = Router(routes=[
Path('/', app=StaticFile(path='index.html')),
PathPrefix('/static', app=StaticFiles(directory='static')),
])
```

Static files will respond with "404 Not found" or "406 Method not allowed"
responses for requests which do not match.
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ nav:
- Requests: 'requests.md'
- WebSockets: 'websockets.md'
- Routing: 'routing.md'
- Static Files: 'staticfiles.md'
- Applications: 'applications.md'
- Test Client: 'test_client.md'
- Debugging: 'debugging.md'
Expand Down

0 comments on commit 352ccda

Please sign in to comment.