Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace WebSocket config/params with URI scheme for all backends #103

Merged
merged 3 commits into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 51 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pip install mangum[redis]==0.9.0b1

## Usage

The `Mangum` adapter class is designed to wrap any ASGI application, accepting various configuration options, returning a callable. It can wrap an application and be assigned to the handler:
The `Mangum` adapter class is designed to wrap any ASGI application and returns a callable. It can wrap an application and be assigned to the handler:

```python
from mangum import Mangum
Expand All @@ -71,6 +71,55 @@ def handler(event, context):
return response
```

## Configuration

The adapter accepts various arguments for configuring lifespan, logging, HTTP, WebSocket, and API Gateway behaviour.

### Usage

```python
handler = Mangum(
app,
enable_lifespan=True,
log_level="info",
api_gateway_base_path=None,
text_mime_types=None,
dsn=None,
api_gateway_endpoint_url=None,
api_gateway_region_name=None
)
```

#### Parameters

- `enable_lifespan` : **bool**

Specify whether or not to enable lifespan support. The adapter will automatically determine if lifespan is supported by the framework unless explicitly disabled.

- `log_level` : **str**

Level parameter for the logger.

- `api_gateway_base_path` : **str**

Base path to strip from URL when using a custom domain name.

- `text_mime_types` : **list**

The list of MIME types (in addition to the defaults) that should not return binary responses in API Gateway.

- `dsn`: **str*

DSN connection string to configure a supported WebSocket backend.

- `api_gateway_endpoint_url` : **str**

The endpoint url to use when sending data to WebSocket connections in API Gateway. This is useful if you are debugging locally with a package such as [serverless-dynamodb-local](https://github.com/99xt/serverless-dynamodb-local).

- `api_gateway_region_name` : **str**

The region name of the API Gateway that is managing the API connections.

## Examples

The examples below are "raw" ASGI applications with minimal configurations. You are more likely than not going to be using a framework, but you should be able to replace the `app` in these example with most ASGI framework applications. Please read the [HTTP](https://erm.github.io/mangum/http/) and [WebSocket](https://erm.github.io/mangum/websocket/) docs for more detailed configuration information.
Expand Down Expand Up @@ -163,11 +212,6 @@ async def app(scope, receive, send):

handler = Mangum(
app,
ws_config={
"backend": "s3",
"params": {
"bucket": "<s3-bucket-to-store-connections>"
}
}
dsn="s3://my-bucket-12345"
)
```
28 changes: 2 additions & 26 deletions docs/http.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,12 @@

Mangum provides support for [HTTP](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api.html) and [REST](https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-rest-api.html) APIs in API Gateway. The adapter class handles parsing the incoming requests and managing the ASGI cycle.

## Configuration
## Usage

```python
handler = Mangum(
app,
enable_lifespan=True,
log_level="info",
api_gateway_base_path=None,
text_mime_types=None,
)
handler = Mangum(app)
```

The adapter class accepts the following optional arguments:

- `enable_lifespan` : **bool** (default=`True`)

Specify whether or not to enable lifespan support. The adapter will automatically determine if lifespan is supported by the framework unless explicitly disabled.

- `log_level` : **str** (default=`"info"`)

Level parameter for the logger.

- `api_gateway_base_path` : **str**

Base path to strip from URL when using a custom domain name.

- `text_mime_types` : **list**

The list of MIME types (in addition to the defaults) that should not return binary responses in API Gateway.

## Binary support

Binary response support is available depending on the `Content-Type` and `Content-Encoding` headers. The default text mime types are the following:
Expand Down
58 changes: 51 additions & 7 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pip install mangum[redis]==0.9.0b1

## Usage

The `Mangum` adapter class is designed to wrap any ASGI application, accepting various configuration options, returning a callable. It can wrap an application and be assigned to the handler:
The `Mangum` adapter class is designed to wrap any ASGI application and returns a callable. It can wrap an application and be assigned to the handler:

```python
from mangum import Mangum
Expand All @@ -71,6 +71,55 @@ def handler(event, context):
return response
```

## Configuration

The adapter accepts various arguments for configuring lifespan, logging, HTTP, WebSocket, and API Gateway behaviour.

### Usage

```python
handler = Mangum(
app,
enable_lifespan=True,
log_level="info",
api_gateway_base_path=None,
text_mime_types=None,
dsn=None,
api_gateway_endpoint_url=None,
api_gateway_region_name=None
)
```

#### Parameters

- `enable_lifespan` : **bool**

Specify whether or not to enable lifespan support. The adapter will automatically determine if lifespan is supported by the framework unless explicitly disabled.

- `log_level` : **str**

Level parameter for the logger.

- `api_gateway_base_path` : **str**

Base path to strip from URL when using a custom domain name.

- `text_mime_types` : **list**

The list of MIME types (in addition to the defaults) that should not return binary responses in API Gateway.

- `dsn`: **str*

DSN connection string to configure a supported WebSocket backend.

- `api_gateway_endpoint_url` : **str**

The endpoint url to use when sending data to WebSocket connections in API Gateway. This is useful if you are debugging locally with a package such as [serverless-dynamodb-local](https://github.com/99xt/serverless-dynamodb-local).

- `api_gateway_region_name` : **str**

The region name of the API Gateway that is managing the API connections.

## Examples

The examples below are "raw" ASGI applications with minimal configurations. You are more likely than not going to be using a framework, but you should be able to replace the `app` in these example with most ASGI framework applications. Please read the [HTTP](https://erm.github.io/mangum/http/) and [WebSocket](https://erm.github.io/mangum/websocket/) docs for more detailed configuration information.
Expand Down Expand Up @@ -163,11 +212,6 @@ async def app(scope, receive, send):

handler = Mangum(
app,
ws_config={
"backend": "s3",
"params": {
"bucket": "<s3-bucket-to-store-connections>"
}
}
dsn="s3://my-bucket-12345"
)
```
Loading