Using Your Local Ruby Environment to Deploy Blockspring Functions

Add a Parameter to Your Function

In this step, you'll add a new input parameter to your function. Your updated function will take a color as an input and pass that color right out.

require 'blockspring'

block = lambda do |request, response|
        name = "Hi! My name is " + request.params["first_name"]
        age = " and my age is " + request.params["age"].to_s
        # add a new input parameter
        color = request.params["color"]

        response.addOutput("intro", name + age)
        # pass our input parameter right out
        response.addOutput("favorite_color", color)


Your new code accesses the color input with request.params["color"] and just passes the color back out using the response.addOutput helper function.

To test, run your function from the command line. Make sure to provide a color key in the JSON input because that connects directly to request.params["color"].

$ echo '{"first_name":"Jennifer","age":32, "color": "#a3b4c5"}' | blockspring run ruby block.rb
{"_blockspring_spec":true,"_errors":[],"intro":"Hi! My name is Jennifer and my age is 32", "favorite_color": "#a3b4c5"}

That's it. Pass inputs in through JSON and they are available in your code with request.params. Now push your updated function to Blockspring and open its webpage.

$ blockspring push
Syncronizing script file ./block.rb
Syncronizing config file ./blockspring.json
$ blockspring open

If you run the function on the site, you'll see an error.

Your function expects request.params["color"], but it can't find it. Blockspring isn't passing a color input parameter because it doesn't know about it yet.


Let's explore how to tell Blockspring about your new input parameter.