Conditional IF Example
Apply condition to the incoming number.
- IF the number is greater than 10: multiply by 10.
- ELSE: reply with a message "The number is not great than 10".
Supporting Concepts
Basic concepts needed for the use case
Topic | Description |
---|---|
API | An API in API AutoFlow is simply an OpenAPI model |
Server | A server accepts and handles the request and response. |
Simulation | Data simulation is a mock data simulated for the purpose of visualizing the data in every step of the workflow.
|
Scope | A scope is a namespace for variables. |
Data Types | Data types describe the different types or kinds of data that you are gonna store and work with. |
Use case specific concepts
Topic | Description |
---|---|
Action conditional/IF | Returns values that fits the condition. |
Action math/calculate | Calculate mathematical expression. |
Details
Send JSON object with a key condition
over HTTP request body.
The goal of the operation is to run a conditional logic:
IF greater than 10
An action is added to perform a math calculation of multiplying by 10
.
For example, if the input number is 15
, the output is
150
ELSE Return
A string value.
The number is not great than 10.
Content
INPUT: HTTP Request
1: Create an API endpoint
Learn how to create an API.
Create an API
From the left navigation, go to the API section and create a new API.
- ID:
sample-conditional
Create an API Path
- Path:
/if
- Method: POST
2. Create a Server Operation
Learn how to create a Server.
Create a Server
From the left navigation, go to the Server section and create a new Server.
- Server ID:
sample-conditional
- Port Number:
1113
Feel free to select your own port number - Linked API:
sample-conditional
(select the API you created above)
Create a Server Operation
- Press the "Add API Operation"
- Select the API endpoint created above
3 : Create Data Simulation using Real Data
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
API Autoflow Postman Collections
cURL
curl --location 'localhost:1113/if' \
--header 'Content-Type: application/json' \
--data '{
"condition": 15
}'
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.
Action(s)
Learn how to create a Actions.
Add actions to transform the data.
1. Apply condition to the input data
IF condition works based on truthy value. There are a few options in getting the boolean result.
(IF): Greater than 10
In this example, we will use the "Value type selector / Comparison" greater-than
to compare the HTTP request body with a number "10".
The two number to compare:
- 1st number: Data from request body
condition
field - 2nd number:
10
SETTINGS
IF: Comparison
data
[request:body > condition
]is greater than to:
number10
Multiply by 10
Math Calculate
SETTINGS
expression: string
10 + number
variables: object
number: data
[request:
body > condition
]
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
body: data
[variables:
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
curl --location 'localhost:1113/if' \
--header 'Content-Type: application/json' \
--data '{
"condition": 15
}'