aws / aws/chalice

Feature request: Pluggable resourceful routing definition

Open
#1,108 4 comments 0 reactions 0 assignees View on GitHub
feature-request
Dominant language
Python
Stars
11.1k
Forks
1k
Avg merge
1d 22h
Merged PRs (30d)
2

Description

In current Chalice, we usually need to define some conditions if we make an endpoint handle various HTTP methods just like following,

```python
@app.route('/', methods=['GET', 'POST'])
def index():
method = app.current_request.method

if method == 'GET':
pass

if method == 'POST':
pass
```

However I guess it can lose readability in some cases
And it would be worse if it needs to handle all CRUD with a single endpoint

Thus, althogh I would be happy if I can define an endpoint like below, what do you think about it? Do you have any plan to support pluggable or classified view definition?

```python
@app.route('/')
class Index(View):
def get(self):
pass

def post(self):
pass
```

or

```python
class Index(View):
def get(self):
pass

def post(self):
pass

app.register_route(Index, '/')
```

or both :)
I prefer the latter one

This looks similar to https://github.com/aws/chalice/issues/487, but I guess slightly difference
As of today, Chalice supports blueprints (as experimental API though), I think development efficiency should be improved if classified view definition and devided routing definition are supported as in the latter example

Contributor guide

Open the contributing guide

Research direction

Read the related discussion in issue #487 and review Chalice's experimental blueprint support first. Compare the proposed @app.route class form with the preferred app.register_route(Index, '/') form, then clarify the routing and view-definition requirements; done means an agreed design and implementation scope for classified HTTP-method handlers.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
api, backend, cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.