Method: FunctionsFramework.typed
- Defined in:
- lib/functions_framework.rb
.typed(name = DEFAULT_TARGET, request_class: nil) ⇒ self
Define a Typed function that responds to HTTP requests.
You must provide a name for the function, and a block that implements the
function. The block should take a single argument representing the request
payload. If a request_type is provided, the argument object will be of
the given decoded type; otherwise, it will be a JSON hash. The block
should return a JSON hash or an object that implements #to_json.
Example
FunctionsFramework.typed "my-sum-function" do |add_request|
{sum: add_request["num1"] + add_response["num2"]}
end
Example with Type
FunctionsFramework.typed "identity",
request_class: MyCustomType do |custom_type|
custom_type
end
168 169 170 171 |
# File 'lib/functions_framework.rb', line 168 def typed(name = DEFAULT_TARGET, request_class: nil, &) global_registry.add_typed(name, request_class: request_class, &) self end |