Skip to content

Commit 6e6e4b0

Browse files
authored
Merge pull request #73 from enter-at/fix/make-docs-great-again
Separate api and collaboration documentation
2 parents 13a58c2 + 938acf8 commit 6e6e4b0

File tree

2 files changed

+121
-123
lines changed

2 files changed

+121
-123
lines changed

README.md

+4-122
Original file line numberDiff line numberDiff line change
@@ -12,120 +12,12 @@ An opinionated Python package that facilitates specifying AWS Lambda handlers.
1212

1313
It includes input validation, error handling and response formatting.
1414

15-
## Contents
15+
## Documentation
16+
Read more about the project motivation and API documentation at:
1617

17-
* [Validators](validators.md)
18-
* [API Reference](source/modules)
18+
- [https://lambda-handlers.readthedocs.io/en/latest/](https://lambda-handlers.readthedocs.io/en/latest/)
1919

20-
## Getting started
21-
22-
Install `lambda-handlers` with:
23-
24-
```bash
25-
pip install lambda-handlers
26-
```
27-
28-
If you are going to use validation, you should choose between
29-
[Marshmallow](https://pypi.org/project/marshmallow/) or
30-
[jsonschema](https://pypi.org/project/jsonschema/).
31-
32-
To install with one of these:
33-
34-
```bash
35-
pip install 'lambda-handlers[marshmallow]'
36-
```
37-
38-
or
39-
40-
```bash
41-
pip install 'lambda-handlers[jsonschema]'
42-
```
43-
44-
### Quickstart
45-
46-
By default the `http_handler` decorator makes sure of parsing the request body
47-
as JSON, and also formats the response as JSON with:
48-
49-
- an adequate statusCode,
50-
- CORS headers, and
51-
- the handler return value in the body.
52-
53-
```python
54-
from lambda_handler import http_handler
55-
56-
@http_handler()
57-
def handler(event, context):
58-
return event['body']
59-
```
60-
61-
### Examples
62-
63-
Skipping the CORS headers default and configuring it.
64-
65-
```python
66-
from lambda_handler import http_handler
67-
from lambda_handlers.response import cors
68-
69-
@http_handler(
70-
cors=cors(origin='localhost', credentials=False),
71-
)
72-
def handler(event, context):
73-
return event['body']
74-
```
75-
76-
Using jsonschema to validate a the input of a User model.
77-
78-
```python
79-
from typing import Dict, Any
80-
81-
from lambda_handler import validators, http_handler
82-
83-
user_schema: Dict[str, Any] = {
84-
'type': 'object',
85-
'properties': {
86-
'user_id': {'type': 'number'},
87-
},
88-
}
89-
90-
91-
@http_handler(
92-
validator=validators.jsonschema(body=user_schema),
93-
)
94-
def handler(event, context):
95-
user = event['body']
96-
return user
97-
```
98-
99-
Using Marshmallow to validate a User model in the input and in
100-
the response body.
101-
102-
```python
103-
from lambda_handler import validators, http_handler
104-
from marshmallow import Schema, fields
105-
106-
107-
class UserSchema(Schema):
108-
user_id = fields.Integer(required=True)
109-
110-
111-
class ResponseSchema(Schema):
112-
body = fields.Nested(UserSchema, required=True)
113-
headers = fields.Dict(required=True)
114-
statusCode = fields.Integer(required=True)
115-
116-
117-
@http_handler(
118-
validator=validators.marshmallow(
119-
body=UserSchema(),
120-
response=ResponseSchema(),
121-
),
122-
)
123-
def handler(event, context):
124-
user = event['body']
125-
return user
126-
```
127-
128-
## Using the source code
20+
## How to collaborate
12921

13022
This project uses [pipenv](https://pipenv.readthedocs.io) to manage its dependencies
13123
and Python environment. You can install it by:
@@ -139,16 +31,6 @@ For that, we suggest using [pyenv](https://github.com/pyenv/pyenv-installer).
13931

14032
### Installation
14133

142-
For production, after you clone this repository,
143-
you can install this project plus dependencies with:
144-
145-
```bash
146-
cd <clone_dest>
147-
make install
148-
```
149-
150-
### Development
151-
15234
For development you should also install the development dependencies,
15335
so run instead:
15436

docs/index.md

-1
This file was deleted.

docs/index.md

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# lambda-handlers
2+
An opinionated Python package that facilitates specifying AWS Lambda handlers.
3+
4+
It includes input validation, error handling and response formatting.
5+
6+
## Contents
7+
8+
* [Validators](validators.md)
9+
* [API Reference](source/modules)
10+
11+
## Getting started
12+
13+
Install `lambda-handlers` with:
14+
15+
```bash
16+
pip install lambda-handlers
17+
```
18+
19+
If you are going to use validation, you should choose between
20+
[Marshmallow](https://pypi.org/project/marshmallow/) or
21+
[jsonschema](https://pypi.org/project/jsonschema/).
22+
23+
To install with one of these:
24+
25+
```bash
26+
pip install 'lambda-handlers[marshmallow]'
27+
```
28+
29+
or
30+
31+
```bash
32+
pip install 'lambda-handlers[jsonschema]'
33+
```
34+
35+
### Quickstart
36+
37+
By default the `http_handler` decorator makes sure of parsing the request body
38+
as JSON, and also formats the response as JSON with:
39+
40+
- an adequate statusCode,
41+
- CORS headers, and
42+
- the handler return value in the body.
43+
44+
```python
45+
from lambda_handler import http_handler
46+
47+
@http_handler()
48+
def handler(event, context):
49+
return event['body']
50+
```
51+
52+
### Examples
53+
54+
Skipping the CORS headers default and configuring it.
55+
56+
```python
57+
from lambda_handler import http_handler
58+
from lambda_handlers.response import cors
59+
60+
@http_handler(
61+
cors=cors(origin='localhost', credentials=False),
62+
)
63+
def handler(event, context):
64+
return event['body']
65+
```
66+
67+
Using jsonschema to validate a the input of a User model.
68+
69+
```python
70+
from typing import Dict, Any
71+
72+
from lambda_handler import validators, http_handler
73+
74+
user_schema: Dict[str, Any] = {
75+
'type': 'object',
76+
'properties': {
77+
'user_id': {'type': 'number'},
78+
},
79+
}
80+
81+
82+
@http_handler(
83+
validator=validators.jsonschema(body=user_schema),
84+
)
85+
def handler(event, context):
86+
user = event['body']
87+
return user
88+
```
89+
90+
Using Marshmallow to validate a User model in the input and in
91+
the response body.
92+
93+
```python
94+
from lambda_handler import validators, http_handler
95+
from marshmallow import Schema, fields
96+
97+
98+
class UserSchema(Schema):
99+
user_id = fields.Integer(required=True)
100+
101+
102+
class ResponseSchema(Schema):
103+
body = fields.Nested(UserSchema, required=True)
104+
headers = fields.Dict(required=True)
105+
statusCode = fields.Integer(required=True)
106+
107+
108+
@http_handler(
109+
validator=validators.marshmallow(
110+
body=UserSchema(),
111+
response=ResponseSchema(),
112+
),
113+
)
114+
def handler(event, context):
115+
user = event['body']
116+
return user
117+
```

0 commit comments

Comments
 (0)