N to 1
Overview
In the below example, if the source is "website_user", the name will be split into first and last name. For other case, in the below example source being "service_user", the values from the input will directly inserted into a new object.
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 condition/switch | Returns values that fits on switch case. If the input value is not in the case list, it returns the value of default. |
Action string/split | Returns array that divides a string into substrings at each Unicode whitespace occurrence with leading and trailing whitespace ignored. |
Details
There are two sources of input:
First input (case 1)
- source:
service_user
- first:
John
- last:
Doe
{
"fast": "John",
"last": "Doe",
"source": "service_user"
}
Second input (case 2)
- source:
website_user
- name:
Peter Parker
{
"name": "Peter Parker",
"source": "website_user"
}
Result
The return should be an object like:
Return 1
{
"first_name": "John",
"last_name": "Doe"
}
Return 2
{
"first_name": "Peter",
"last_name": "Parker"
}
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-data-transformation
Create an API Path
- Path:
/n-to-1
- 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-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
- 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
First input (case 1)
API Autoflow Postman Collections
cURL
{
"fast": "John",
"last": "Doe",
"source": "service_user"
}
Second input (case 2)
{
"name": "Peter Parker",
"source": "website_user"
}
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.
Case 1
Case 2
Action(s)
Learn how to create a Actions.
Add actions to transform the data.
1. IF the data is from Website vs Service
SWITCH based on the [input: source
]
Condition Switch
SETTINGS
SWITCH: data
[input:
source
]
(Case 1): Look for the source "website_user"
If the source has the value website_user
, it will split the string.
String Split
Learn how to use string/split actions.
SETTINGS
string/split data
[request:
body > name
]
OUTPUT
variables:
output
RETURN
SETTINGS
RETURN object
first_name data
[variables:
output > 0
]last_name data
[variables:
output > 1
]
(Case 2): Look for the source "service_user"
Return
SETTINGS
RETURN object
first_name data
[variables:
body > first
]last_name data
[variables:
body > last
]
DEFAULT
Return: string
No match found
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
First input (case 1)
{
"fast": "John",
"last": "Doe",
"source": "service_user"
}
Second input (case 2)
{
"name": "Peter Parker",
"source": "website_user"
}