templates/crystal/example/src/handler.cr in faastruby-0.3.7 vs templates/crystal/example/src/handler.cr in faastruby-0.3.8
- old
+ new
@@ -6,11 +6,11 @@
def handler(event : FaaStRuby::Event) : FaaStRuby::Response
# event.body : String | Nil
# event.headers : Hash(String, String)
# event.context : String | Nil
# query_params : Hash(String, String)
- data = JSON.parse(event.body.not_nil!) rescue {} of String => String
+ name = event.body ? JSON.parse(event.body.not_nil!)["name"] : "World"
# FUNCTION RESPONSE
#
# You can render text, json, yaml, html or js. Example:
# render html: "<p>Hello World!</p>"
# render yaml: {"hello" => "world!"}
@@ -21,7 +21,7 @@
#
# Headers:
# The 'Content-Type' header is automatically set when you use 'render'.
# You can set custom headers using a Hash(String, String). Example:
# render text: "It Works!", headers: {"TransactionId" => 23928}
- render text: "Hello, #{data["name"]? || "World"}!\n"
+ render text: "Hello, #{name}!\n"
end