Designer

Before you start

For this guide, we will need the following:

  • An Elsa Server project

  • An Elsa Studio instance

    docker pull elsaworkflows/elsa-studio-v3:latest
    docker run -t -i -e ASPNETCORE_ENVIRONMENT='Development' -e HTTP_PORTS=8080 -e ELSASERVER__URL=https://localhost:5001/elsa/api -p 14000:8080 elsaworkflows/elsa-studio-v3:latest

Port Numbers

When starting Elsa Studio, make sure you provide it with the correct URL to the Elsa Server application.

For example, if Elsa Server runs on https://localhost:5001, the Docker command should look like this:

docker run -t -i -e ASPNETCORE_ENVIRONMENT='Development' -e HTTP_PORTS=8080 -e ELSASERVER__URL=https://localhost:5001/elsa/api -p 14000:8080 elsaworkflows/elsa-studio-v3:latest

Please return here when you are ready.

Workflow Overview

We will define a new workflow called GetUser. The purpose of the workflow is to handle inbound HTTP requests by fetching a user by a given user ID from a backend API and writing them back to the client in JSON format.

For the backend API, we will use reqres.in, which returns fake data using real HTTP responses.

Our workflow will parse the inbound HTTP request by getting the desired user ID from a route parameter and use that value to make an API call to reqres.

The following is an example of such an HTTP request that you can try right now from your browser: https://reqres.in/api/users/2

The response should look similar to this:

{
    "data": {
        "id": 2,
        "email": "janet.weaver@reqres.in",
        "first_name": "Janet",
        "last_name": "Weaver",
        "avatar": "https://reqres.in/img/faces/2-image.jpg"
    },
    "support": {
        "url": "https://reqres.in/#support-heading",
        "text": "To keep ReqRes free, contributions towards server costs are appreciated!"
    }
}

Our workflow will essentially be a proxy sitting in front of the reqres API and return a portion of the response.

Designing the Workflow

Follow these steps to create the workflow using Elsa Studio.

1

Create Get User Workflow

Create a new workflow called Get User

2

Add Activities

Add and connect the following activities to the design surface:

  • HTTP Endpoint

  • Set Variable

  • HTTP Request (flow)

  • HTTP Response (for 200 OK)

  • HTTP Response (for 404 Not Found)

3

Create Variables

Create the following variables:

Name
Type
Storage

RouteData

ObjectDictionary

Workflow Instance

UserId

string

Workflow Instance

User

Object

Workflow Instance

4

Configure Activities

Configure the activities as follows:

HTTP Endpoint

Property
Value
Syntax

Path

users/{userid}

Default

Supported Methods

Get

Default

Set Variable

Property
Value
Syntax

Variable

UserId

Default

Value

return Variables.RouteData["userid"];

C#

HTTP Request (flow)

Property
Value
Syntax

Expected Status Codes

200, 404

Default

Url

return $"https://reqres.in/api/users/{Variables.UserId}";

C#

Method

GET

Default

HTTP Response (200)

Property
Value
Syntax

Status Code

OK

Default

Content

variables.User.data

JavaScript

HTTP Response (404)

Property
Value
Syntax

Status Code

NotFound

Default

Content

User not found

Default

5

Connect Activities

Connect each activity to the next. Ensure that you connect the 200 and 404 outcomes of the HTTP Request (flow) activity to the appropriate HTTP Response activity.

6

Publish

Publish the workflow.

The final result should look like this:

Running the Workflow

Since the workflow uses the HTTP Endpoint activity, it will trigger when we send an HTTP request to the /api/workflows/users/{userId} path.

Try it out by navigating to http://localhost:13000/api/workflows/users/2.

The response should look similar to this:

{
    "id": 2,
    "email": "janet.weaver@reqres.in",
    "first_name": "Janet",
    "last_name": "Weaver",
    "avatar": "https://reqres.in/img/faces/2-image.jpg"
}

Summary

In this guide, we learned how to design a workflow using Elsa Studio.

We leveraged the HttpEndpoint activity and used is as a trigger to start the workflow.

The workflow is able to read route parameters and store it in a variable, which we then used as an input to send an API call to the reqres API that in turn returns the requested user.

We have also seen how to handle various responses from reqres: 200 OK and 404 Not Found

The workflow created in this guide can be found here.

Last updated