Core Nodes
Switch

Switch Node

Control the flow of your BuildShip workflow based on switch statements with the Switch Node. The switch node evaluates an expression and then executes the corresponding flow that matches the expression’s result.

Switch Node

Switch Node Anatomy

The Switch node consists of the following components:

Switch Node

Expression

The Expression input is the main expression whose value is to be evaluated for the Switch Case.

Example Input:

Query.type // to use switch case on the type parameter in the query
Switch Node

Cases

The switch node will evaluate the value of the specified expression and execute the corresponding case that matches the expression's result.

Example Input:

"image" // this will check if Query.type === "image"
💡

The expression and the case fields of the switch node can be any of the following types: - string - number - boolean

Switch Node

Next Case Toggle

The Next Case Toggle exists on every switch flow. When toggled to true, it will continue to execute its subsequent case. We can think of this Next Case Toggle like a switch case without a break statement.

If a return statement is added inside a case, the Next Case Toggle will be ignored.

Default Case

If there’s no match specified in the "Case" inputs, control is transferred to the flow under the "Default" case.

Example Implementation

Let us understand how to use the Switch Node with an example.

Use Case

We need a workflow that generates assets for an end user. Given the prompt and type of an asset for generation, we need to implement the switch node to process different flows depending on the type of the asset specified by the user.

Request Structure

This example workflow will be a REST API type workflow using the REST API Call Trigger as the starting point for our workflow. The REST API Call Trigger will process the incoming request. Let’s say the incoming HTTP Request is a GET Request and looks like this:

Switch Node

Having two query key value pairs: type specifying the type of asset to generate, and prompt the prompt to be passed for the asset generation.

Expression

If we need to apply the switch node for a query parameter with the key type in the incoming HTTP Request, then we need to add Query.type.

Cases

We need to apply different flows for the different values of the type query parameter, which let’s say defines the type of asset a user wishes to generate. For our example, we assume the user can pass in any of these values:

  • Image
  • Video
  • Animation
  • Audio

So the value of the type query parameter can be: "image", "video", "animation", "audio". We can add these four values as our cases.

After defining the cases, we get 5 different branches for each of the specified types and one for the “Default Case” which is a fallback case - i.e. if there’s no match specified in the "case" inputs, control is transferred to the flow under the "default" case. For the Default case, we can simply add a return node saying that the type is undefined.

Return

To return the value let’s add a return node and set its value to Switch to return the generated asset.

Our final workflow will look something like this:

Switch Node

Need Help?

  • 💬
    Join BuildShip Community

    An active and large community of no-code / low-code builders. Ask questions, share feedback, showcase your project and connect with other BuildShip enthusiasts.

  • 🙋
    Hire a BuildShip Expert

    Need personalized help to build your product fast? Browse and hire from a range of independent freelancers, agencies and builders - all well versed with BuildShip.

  • 🛟
    Send a Support Request

    Got a specific question on your workflows / project or want to report a bug? Send a us a request using the "Support" button directly from your BuildShip Dashboard.

  • ⭐️
    Feature Request

    Something missing in BuildShip for you? Share on the #FeatureRequest channel on Discord. Also browse and cast your votes on other feature requests.