Chalice: Return 201 (created) and set Location header

Created on 25 Aug 2016  路  4Comments  路  Source: aws/chalice

Hi, it would be great to be able to set the return status to 201 and provide the Location HTTP header in the response. This would make Chalice much more useful to create RESTFul APIs.

Thanks,
Lars

feature-request

Most helpful comment

The latest version of 0.6.0 now makes this possible. The default JSON response is still preserved, but you can return a chalice.Response instance which allows you to specify custom headers including Location:

from chalice import Chalice, Response

app = Chalice(app_name='custom-response')


@app.route('/')
def index():
    return Response(body='',
                    status_code=201,
                    headers={'Location': 'https://...'})

Let me know if you have any questions/feedback about this feature.

All 4 comments

Not currently possible, but I'd like to add this. Marking as a feature request.

Next to 201, I'd also like to return 202, and 204 as well as 405, 410, 423, ...
For 4xx and 5xx, maybe can be as simple as raise HttpError(status_code, description) ?

@stannie, 405 has just been addressed in #160

The latest version of 0.6.0 now makes this possible. The default JSON response is still preserved, but you can return a chalice.Response instance which allows you to specify custom headers including Location:

from chalice import Chalice, Response

app = Chalice(app_name='custom-response')


@app.route('/')
def index():
    return Response(body='',
                    status_code=201,
                    headers={'Location': 'https://...'})

Let me know if you have any questions/feedback about this feature.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

montao picture montao  路  4Comments

michaeldimchuk picture michaeldimchuk  路  3Comments

rupello picture rupello  路  4Comments

mrdavidhanson picture mrdavidhanson  路  3Comments

kortina picture kortina  路  3Comments