Skip to main content
?

Object Value Convert Unit

Overview

Converting units from one type to another (ex. Mbps to Kbps and vice versa).


Supporting Concepts

Basic concepts needed for the use case
TopicDescription
APIAn API in API AutoFlow is simply an OpenAPI model
ServerA server accepts and handles the request and response.
SimulationData simulation is a mock data simulated for the purpose of visualizing the data in every step of the workflow.
  • Simulated data is NOT the real data but a sample data you create.
  • To use real data, use the Transaction feature to capture the data you send from Postman or CURL.
ScopeA scope is a namespace for variables.
Data TypesData types describe the different types or kinds of data that you are gonna store and work with.
Use case specific concepts
TopicDescription
Action
conditional/SWITCH
Returns values that fits the condition.
Action
math/calculate
Calculate mathematical expression.

Detail

The HTTP request has an input:

Test case 1

{
"speed" : 1000000,
"unit" : "kbps"
}

Test case 2

{
"speed" : 1000,
"unit" : "mbps"
}

The goal of the operation is to merge the object into a flatter structure:

Result 1

{
"speed": 1000,
"unit": "mbps"
}

Result 2

{
"speed": 1000000,
"unit": "kbps"
}

Content

INPUT: HTTP Request

1: Create an API endpoint

Required Concepts

Learn how to create an API.

Create an API

From the left navigation, go to the API section and create a new API.

Create API
  • ID: sample-data-transformation
Create an API Path
Create API Path
  • Path: /obj-values-convert-unit
  • Method: POST

2. Create a Server Operation

Required Concepts

Learn how to create a Server.

Create a Server

From the left navigation, go to the Server section and create a new Server.

Create Server
  • Server ID: sample-data-transformation
  • Port Number: 1114 Feel free to select your own port number
  • Linked API: sample-data-transformation (select the API you created above)
Create a Server Operation
Create Server Operation
  • Press the "Add API Operation"
  • Select the API endpoint created above

3 : Create Data Simulation using Real Data

Required Concepts

Learn how to create a Simulation.

We will use the "real data" to create the test simulation.

1. Send a HTTP request from Postman or CURL

Test Case 1

Send Postman Request

API Autoflow Postman Collections

cURL
curl --location 'localhost:1114/obj-values-convert-unit' \
--header 'Content-Type: application/json' \
--data '{
"speed" : 1000000,
"unit" : "kbps"
}'

Test Case 2

Send Postman Request

API Autoflow Postman Collections

cURL
curl --location 'localhost:1114/obj-values-convert-unit' \
--header 'Content-Type: application/json' \
--data '{
"speed" : 1000,
"unit" : "mbps"
}'
2. Check the data is received by the server endpoint

API Autoflow captures the data received and it can be used to create data simulation.

Test Case 1

Simulation

Test Case 1

Simulation

Action(s)

Required Concepts

Learn how to create a Actions.

Add actions to transform the data.

1. Apply logic based on the mbps vs. kbps

The condition looks at the request: body > unit and applies case that matches.

Condition Switch
Condition Switch
SETTINGS

SWITCH: data

request: body > unit


Case 1: If the unit is kbps
Math Calculate

Create two variables input and unit. In the expression, divide the two variables.

Case 1 Math Calculate
SETTINGS

expression: string input / unit
variables: object

input: data
[variables: body > speed]
unit: number 1000

OUTPUT

variables: output

Return

Create a NEW object in the final format.

SETTINGS
Case 1 Return

speed: data

variables: output

unit: string mbps


Case 2: If the unit is mbps
Case 2
Math Calculate

Create two variables input and unit. In the expression, this time we are multiplying the two variables.

SETTINGS
Case 2 Math Calculate

expression: string input * unit

input: data
variables: body > speed
unit: number 1000

OUTPUT

variables: output

Return

Create a NEW object in the final format.

SETTINGS
Case 2 Return

speed: data

variables: output

unit: string kbps


DEFAULT
Default

Return a string value of Invalid data type

OUTPUT

variables: output

OUTPUT: HTTP Response

1. Create a NEW object and map the IP and Subnet

Both the action's output and HTTP response body are set to variables: output. There's no change that needs to be made.

HTTP Response
SETTINGS
Server Workflow Default Output

body: data
[variables: output]

Mapping the action output to the HTTP response output
  • Data referenced in HTTP response is what gets sent back to the client.
  • Map the output from the actions to be sent back.

NOTE: By default, the action output is set to variable output. If you intend to keep each action's output without it being overwritten by the next action, simply rename the output location in the action's output.

2. Test the API with Postman or CURL

cURL for Test Case 1
curl --location 'localhost:1114/obj-values-convert-unit' \
--header 'Content-Type: application/json' \
--data '{
"speed" : 1000000,
"unit" : "kbps"
}'
cURL for Test Case 2
curl --location 'localhost:1114/obj-values-convert-unit' \
--header 'Content-Type: application/json' \
--data '{
"speed" : 1000,
"unit" : "mbps"
}'