Method: FunctionsFramework::Registry#add_http
- Defined in:
- lib/functions_framework/registry.rb
#add_http(name, &block) ⇒ self
Add an HTTP function to the registry.
You must provide a name for the function, and a block that implemets the
function. The block should take a single Rack::Request argument. It
should return one of the following:
- A standard 3-element Rack response array. See https://github.com/rack/rack/blob/master/SPEC
- A
Rack::Responseobject. - A simple String that will be sent as the response body.
- A Hash object that will be encoded as JSON and sent as the response body.
75 76 77 78 79 80 81 82 |
# File 'lib/functions_framework/registry.rb', line 75 def add_http name, &block name = name.to_s @mutex.synchronize do raise ::ArgumentError, "Function already defined: #{name}" if @functions.key? name @functions[name] = Function.http name, &block end self end |