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

Return 201 (created) and set Location header #110

Closed
laolsson opened this issue Aug 25, 2016 · 4 comments
Closed

Return 201 (created) and set Location header #110

laolsson opened this issue Aug 25, 2016 · 4 comments

Comments

@laolsson
Copy link

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

@jamesls
Copy link
Member

jamesls commented Aug 26, 2016

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

@stannie
Copy link

stannie commented Sep 11, 2016

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) ?

@grahamlyons
Copy link
Contributor

@stannie, 405 has just been addressed in #160

@jamesls
Copy link
Member

jamesls commented Feb 24, 2017

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.

@jamesls jamesls closed this as completed Feb 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants