Merge Object
Overview
Received data in a nested object and merge into a flatter structure.
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 object/merge | Returns new object which Merges two 'object' into one. |
Detail
The HTTP request has an input:
{
"ChildA": {
"fieldA": "valueA"
},
"ChildB": {
"fieldB": "valueB"
}
}
The goal of the operation is to merge the object into a flatter structure:
{
"fieldA": "valueA",
"fieldB": "valueB"
}
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.
![Create API](/ent/assets/images/create-api-7986cdbc6b7ebb391d08a32d5ccc7e7b.jpg)
- ID:
sample-data-transformation
Create an API Path
![Create API Path](/ent/assets/images/create-api-path-11a3fcd158349c86ad84a82cfc2f2c96.jpg)
- Path:
/obj-merge
- 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.
![Create Server](/ent/assets/images/create-server-edfae2a385f7169ee19a7933e887202e.jpg)
- 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](/ent/assets/images/server-add-api-operation-a1d1dbd441fcb74c330e099ce6b85790.jpg)
- 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
![Send Postman Request](/ent/assets/images/postman-4e8a5b302c87a8ca6ca7274fc5ba9eea.jpg)
API Autoflow Postman Collections
cURL
curl --location 'localhost:1114/obj-merge' \
--header 'Content-Type: application/json' \
--data '{
"ChildA": {
"fieldA": "valueA"
},
"ChildB": {
"fieldB": "valueB"
}
}
}'
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.
![Simulation](/ent/assets/images/simulation-b37c6bbd61fc528bce6b72341ef12424.jpg)
Action(s)
Learn how to create a Actions.
Add actions to transform the data.
1. Merge the object
You can cut and paste the Bits to Hex object from the end of this document to the action's object.
Variable Set Action
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
- 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/obj-merge' \
--header 'Content-Type: application/json' \
--data '{
"ChildA": {
"fieldA": "valueA"
},
"ChildB": {
"fieldB": "valueB"
}
}
}'