Parse JSON file to API
The below content is from the quickstart tutorial.
01 - JSON output to API
The most easiest way for you to convert an existing command or script to API is if it outputs to a supported output such as JSON.
Simply supply your required run command, view all the available options here.
Prepare sample data
- Ready an existing JSON file or script that outputs JSON, else save an example JSON file eg.
 
heroes.json
{
    "message": "hero ouput",
    "heroes": [
        {
            "name": "batman",
            "identity": "bruce"
        },
        {
            "name": "superman",
            "identity": "clark"
        }
    ]
}
Review configuration
- Set the interface name and/or http route on how you want to access the output
 - Specify the command you'd like to run
 - Set the parse option to json
 - Place the configuration into your 
configsdirectory - Stop/Start the binary
 
./airpipe --api-key enter-your-api-key --config-dir configs/
tutorial-json-cat-to-api.yml
name: json-cat-to-api
description: run cat command to read json file
interfaces:
  tutorial/json-cat-to-api:
    output: http # as we have not specified a method it will default to a GET route
    
    actions:
      - name: RunCommand
        command:
          run: cat heroes.json # this can be any command or script that outputs json
          parse:
            data_type: json # this will ensure it attempts to process the data as json
Test
As we've specified http we can just run this in our browser or a perform a simple curl
http://0.0.0.0:4111/tutorial/json-cat-to-api
HTTP Response
{
    "data": {
        "RunCommand": {
            "data": {
                "heroes": [
                    {
                        "identity": "bruce",
                        "name": "batman"
                    },
                    {
                        "identity": "clark",
                        "name": "superman"
                    }
                ],
                "message": "hero ouput"
            },
            "time.ms": 1
        }
    }
}