Skip to main content
?

Binary Decimal to Bit Flag

Overview

Receive flag in decimal and convert binary flag

For example

Binary 1101 represent 4 flags A, B, C, D where if the bit is set, then flag is True


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
data/binary-to-flag
Converts the given datetime to unix time.
Action
variable/set
This Action set variable.
Action
iteration/map
Iterate over array of data mapping result to each array position.
Action
object/put
This action returns new object which puts the given 'value' under 'key' in 'object'

Detail

The HTTP request has an input:

{
"flag" : 13
}

The goal of the operation is to convert the decimal into a :

{
"flagA": true,
"flagB": true,
"flagC": false,
"flagD": true
}

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: /binary-dec-to-bit-flag
  • 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
Send Postman Request

API Autoflow Postman Collections

cURL
curl --location 'localhost:1114/bit-to-flag' \
--header 'Content-Type: application/json' \
--data '{
"flag" : 13
}'
2. Create a Test Simulation from the Received Data

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

Simulation

Action(s)

Required Concepts

Learn how to create a Actions.

You can add actions to transform the data.

1. Converts decimal to binary

Decimal to Binary Action

Binary action coverts the decimal into either enum or boolean

Integration Bit To Flag
SETTINGS

integer: data

[request: body > flag]

size: number

0

mode: enum

boolean

OUTPUT

variables: binary

2. Create a list of flag names

Variable Set Action

Since flag names need to be customizable, we can create a new array with flag names.

Variable Set Flag Table
SETTINGS

value: array

string
flagA
string
flagB
string
flagC
string
flagD
OUTPUT

variables: flag-names

3. Create an empty object to store the final data

Variable Set Action

As we iterate over the binary, we need an empty object to start putting the new value.

Variable Set Final Table
SETTINGS

value: object

OUTPUT

variables: output

4. Iterate over the binary

Required Concepts

Learn how to create a iteration/map.

Iteration Map Action
Iteration Map

Iterable: data variable: binary
SCOPE: string loop-var

We will iterate over the array created with the binary in step 1.

Put New value in the empty object
Object/Put

As we iterate over the array of binary, we can create a new key:value and insert it in the empty array created in step 3.

Object Put
SETTINGS

object: data

[variables: output]

key: data

[variables: flag-name > Scope::(loop-var: index)]

value: data
[loop-var: value]

OUTPUT

variables: output

Dynamic referencing

Notice the data referencing for the key is again referencing loop-var: index. It is common to reference other data within the reference.

For example,

  • As the iteration loops over the array flag-names, it will generate index numbers starting from 0.
  • We are simply inserting the index number as part of the key's reference.
  • For the first loop where the index is 0, The key's reference would be variables: flag-names > 0, which is flagA

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
curl --location 'localhost:1114/bit-to-flag' \
--header 'Content-Type: application/json' \
--data '{
"flag" : 13
}'