Rest API endpoint

In this video, we will walk through everything you need to know about "Building a REST API" in Easyflow.

  • Let’s first create a new flow with the title Build Rest API using Easyflow.

  • With Easyflow, you can quickly and easily create APIs that can be used by your backend systems, applications, and customers, without the need to write a single line of code.

  • Additionally, your APIs can send and retrieve data from hundreds of partners applications and databases, including a robust library of built-in connectors.

  • With Easyflow, you can build any logic with unlimited flexibility. The drag and drop "Workflow designer" allows you to tailor their logic to a granular level, similarly to how they would write code.

  • For example, you can build API on top of many popular databases such as “Amazon Dynamodb”, “Mongo db”, “postres ql”, “builtin datablocs” and many.

To make this demo simple, we will build an API on top of Google Sheets.

  • First, let’s configure the Google Sheets connectors after choosing the “Add a Row” option from its operations list.

  • To allow users to send input requests to "Google Sheets", we will create variables of type "Start Event".

  • We will create 5 variables: "first name", "last name", "user id", "country", "city", "role", and "email".

  • Next, we will map all these variables to the "Google Sheets" data field.

  • Remember to save your changes and set "Google Sheets” as a starting point.

  • In order to call the workflow as an API from outside of Easyflow, you will need its endpoint URL.

  • This URL can be used to invoke the API from a web browser, postman or your code.

  • Click on the i icon in the toolbar of the workflow designer then copy the auto-generated URL for your API endpoint.

  • From the postman application, create a new API request using the GET method and paste the "copied URL" into the request.

  • You will notice the URL contains many parameters that are structured as follows:

    1. Path parameters: Consist of the workflow identifier. It’s a unique identifier per workflow.

    2. key query parameter: The access key that is used to authenticate your workflow.

    3. async query parameters: To make a transactional or asynchronous call to the API. possible values are true or false. Default is false.

    4. List of custom query parameters: Consists all your created “Start Event” variables.

  • Let's assign a value for each of the parameters and send an API request. As you can see, the call was successful and the response returned from Google Sheets without any modifications.

  • By checking the "Google Sheets" file, we can confirm that the data has been successfully inserted.

  • Another way to call the API is by running it from inside the Workflow designer by pressing the run button located in the toolbar.

  • You will notice that the input box gives you the capability to set values for each of the "Start Even" variable input parameters. Let’s try it out and see the results.

  • As we can see in the preview results, the data returned is as expected.

To prepare for the next example, we will re-configure the Google Sheets step by making the “user id” a random UUID instead of being inserted by the user.

One of the common practices when building an API is to return a custom response.

  • To accomplish our goal, we can use the Mapper connector as the second step in the workflow and configure it by building a JSON formatted object that returns a “status code” and the generated “user id” from the initial step.

  • By executing the API from postman, we will notice that the data gets inserted into “Google Sheets” as expected.

Let's take this example further:

  • Instead of generating the UUID directly inside the "Google Sheets" step, we will create a variable of type "Workflow" named "user id" and assign it a UUID using the "variable setter" connector as an initial step.

  • Then we will map the “user id” variable to each of the “Google Sheets” and “Response” steps.

  • Remember to set the Variable Setter as a starting point.

  • When testing the API using Postman, we can see that the response is returning the auto generated "user id" as expected and that the data has been inserted into "Google Sheets".

You can also call the Workflow API from a postman by using the POST method.

You can pass all the "Start Event" custom parameters as a key pair JSON request through the POST method.

  • Suppose you want to extend this workflow to handle two use case scenarios:

    1. First, to insert data into the Google Sheet using the steps from the previous example.

    2. Second, to retrieve a record from Google Sheets based on "user id"

  • To accomplish this scenario, we will create a “Start Event” variable named “Type”. Then, by using a Mapper as the initial step, we will create 2 paths based on the “type” variable value as follows:

    1. If the "type" variable equals INSERT, then the insertion path into Google Sheets will be executed.

    2. If the "type" variable equals SEARCH, a new path that retrieves data from Google Sheets will take place. The results will be filtered based on "user id".

  • By running the workflow from postman, we can test the Search logic and confirm that the data is returned as expected.

Thank you for watching this video.

Please feel free to contact us if you have any questions.

Last updated