Cannot find a way to set a HTTP status code
NDuggan opened this issue · 11 comments
As a quick monkey patch @alexellis and I have amended my local index.rb to do the following:
get '/*' do
res, res_headers, status_code = handler.run request.body, request.env
headers = res_headers
status status_code
return res
end
The approach looks good to me. It should also support default 200 success and 500 internal server status codes in the case that none are provided so we can maintain backwards compatibility with the current handler. I would happy to review it if you submit the PR @NDuggan
cc @alexellis
I think that ruby-http has some adoption, but probably quite minimal usage at present: https://github.com/search?l=Markdown&q=%22lang%3A+ruby-http%22&type=Code
Changing the signature may make sense to get some consistency between templates.
We could try to mirror this Python example, but in Ruby:
def handle(event, context):
return {
"statusCode": 200,
"body": {
"key": "value"
},
"headers": {
"Location": "https://www.example.com/"
}
}Kevin do you have any appetite for taking this?
Yeah let me give this one a shot
def handle(event, context): return { "statusCode": 200, "body": { "key": "value" }, "headers": { "Location": "https://www.example.com/" } }
@alexellis Is this still the desired contract of handle? I'm currently using this template, and created a fix for setting the headers #7. Seeing this I may just as well change the method to reflect this. Should I create an PR with this?
I am wary about making changes which are not backwards compatible.
Today we have the following:
return body, response_headers
Can we return an optional third parameter for the status code or not?
Can we return an optional third parameter for the status code or not?
Sure -> #9
Can this be closed, since #9 has been merged?
Yes, thank you!
Did you see this post btw? https://blog.alexellis.io/faas-for-the-rubyist/
Did you see this post btw? https://blog.alexellis.io/faas-for-the-rubyist/
Yes I saw it, it popped up on Reddit. Good and extensive intro post.