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::Response object.
  • 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.

Parameters:

  • name (String)

    The function name

  • block (Proc)

    The function code as a proc

Returns:

  • (self)


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