Skip to content

Commit edb900d

Browse files
Replace WebSocket config/params with URI scheme for all backends (#103)
* Refactor parameters for websocket backends to use connection strings
1 parent 29c14d6 commit edb900d

File tree

16 files changed

+504
-612
lines changed

16 files changed

+504
-612
lines changed

README.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pip install mangum[redis]==0.9.0b1
4848

4949
## Usage
5050

51-
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:
51+
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:
5252

5353
```python
5454
from mangum import Mangum
@@ -71,6 +71,55 @@ def handler(event, context):
7171
return response
7272
```
7373

74+
## Configuration
75+
76+
The adapter accepts various arguments for configuring lifespan, logging, HTTP, WebSocket, and API Gateway behaviour.
77+
78+
### Usage
79+
80+
```python
81+
handler = Mangum(
82+
app,
83+
enable_lifespan=True,
84+
log_level="info",
85+
api_gateway_base_path=None,
86+
text_mime_types=None,
87+
dsn=None,
88+
api_gateway_endpoint_url=None,
89+
api_gateway_region_name=None
90+
)
91+
```
92+
93+
#### Parameters
94+
95+
- `enable_lifespan` : **bool**
96+
97+
Specify whether or not to enable lifespan support. The adapter will automatically determine if lifespan is supported by the framework unless explicitly disabled.
98+
99+
- `log_level` : **str**
100+
101+
Level parameter for the logger.
102+
103+
- `api_gateway_base_path` : **str**
104+
105+
Base path to strip from URL when using a custom domain name.
106+
107+
- `text_mime_types` : **list**
108+
109+
The list of MIME types (in addition to the defaults) that should not return binary responses in API Gateway.
110+
111+
- `dsn`: **str*
112+
113+
DSN connection string to configure a supported WebSocket backend.
114+
115+
- `api_gateway_endpoint_url` : **str**
116+
117+
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).
118+
119+
- `api_gateway_region_name` : **str**
120+
121+
The region name of the API Gateway that is managing the API connections.
122+
74123
## Examples
75124

76125
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.
@@ -163,11 +212,6 @@ async def app(scope, receive, send):
163212

164213
handler = Mangum(
165214
app,
166-
ws_config={
167-
"backend": "s3",
168-
"params": {
169-
"bucket": "<s3-bucket-to-store-connections>"
170-
}
171-
}
215+
dsn="s3://my-bucket-12345"
172216
)
173217
```

docs/http.md

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,12 @@
22

33
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.
44

5-
## Configuration
5+
## Usage
66

77
```python
8-
handler = Mangum(
9-
app,
10-
enable_lifespan=True,
11-
log_level="info",
12-
api_gateway_base_path=None,
13-
text_mime_types=None,
14-
)
8+
handler = Mangum(app)
159
```
1610

17-
The adapter class accepts the following optional arguments:
18-
19-
- `enable_lifespan` : **bool** (default=`True`)
20-
21-
Specify whether or not to enable lifespan support. The adapter will automatically determine if lifespan is supported by the framework unless explicitly disabled.
22-
23-
- `log_level` : **str** (default=`"info"`)
24-
25-
Level parameter for the logger.
26-
27-
- `api_gateway_base_path` : **str**
28-
29-
Base path to strip from URL when using a custom domain name.
30-
31-
- `text_mime_types` : **list**
32-
33-
The list of MIME types (in addition to the defaults) that should not return binary responses in API Gateway.
34-
3511
## Binary support
3612

3713
Binary response support is available depending on the `Content-Type` and `Content-Encoding` headers. The default text mime types are the following:

docs/introduction.md

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pip install mangum[redis]==0.9.0b1
4848

4949
## Usage
5050

51-
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:
51+
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:
5252

5353
```python
5454
from mangum import Mangum
@@ -71,6 +71,55 @@ def handler(event, context):
7171
return response
7272
```
7373

74+
## Configuration
75+
76+
The adapter accepts various arguments for configuring lifespan, logging, HTTP, WebSocket, and API Gateway behaviour.
77+
78+
### Usage
79+
80+
```python
81+
handler = Mangum(
82+
app,
83+
enable_lifespan=True,
84+
log_level="info",
85+
api_gateway_base_path=None,
86+
text_mime_types=None,
87+
dsn=None,
88+
api_gateway_endpoint_url=None,
89+
api_gateway_region_name=None
90+
)
91+
```
92+
93+
#### Parameters
94+
95+
- `enable_lifespan` : **bool**
96+
97+
Specify whether or not to enable lifespan support. The adapter will automatically determine if lifespan is supported by the framework unless explicitly disabled.
98+
99+
- `log_level` : **str**
100+
101+
Level parameter for the logger.
102+
103+
- `api_gateway_base_path` : **str**
104+
105+
Base path to strip from URL when using a custom domain name.
106+
107+
- `text_mime_types` : **list**
108+
109+
The list of MIME types (in addition to the defaults) that should not return binary responses in API Gateway.
110+
111+
- `dsn`: **str*
112+
113+
DSN connection string to configure a supported WebSocket backend.
114+
115+
- `api_gateway_endpoint_url` : **str**
116+
117+
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).
118+
119+
- `api_gateway_region_name` : **str**
120+
121+
The region name of the API Gateway that is managing the API connections.
122+
74123
## Examples
75124

76125
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.
@@ -163,11 +212,6 @@ async def app(scope, receive, send):
163212

164213
handler = Mangum(
165214
app,
166-
ws_config={
167-
"backend": "s3",
168-
"params": {
169-
"bucket": "<s3-bucket-to-store-connections>"
170-
}
171-
}
215+
dsn="s3://my-bucket-12345"
172216
)
173217
```

0 commit comments

Comments
 (0)