mHUB - cURL Primer

CURL defaults to performing a GET command:

curl http://localhost:8080/matchITHub/engines

{"status":"OK","ids":""}

Or you can specify the command with -X:

curl -X GET http://localhost:8080/matchITHub/engines

{"status":"OK","ids":""}

You can specify POST data with --data or -d (here you will need to URL encode any data):

curl -X POST --data "activation_code=pDARI0Yxfb%2FBnBKw0CjsgeMtUFlei5X3uSZvNOOtjwWpfLupRk6%2Fj8v7TnRMQHG9uFXvXTLORg7omI%2FMQjNNZcGBEFew5%2FgoAG7xRa0mUbh9FEXpJOxQgT8ualYqW9WZibPH2K3SXziD4WySGQpIbCSty%2Bssacyq4l1OMnHi1m%2BjhkhqxKNtyvcuwGYg6MmleDRWTY%2FuY8JJfuR9A6v8yQrggqHAhbh%2Bw5STv3g2Z%2FajAmQa9Fs7TzZ%2FzileiDZ%2F" http://localhost:8080/matchITHub/engines

{"status":"OK","engine":1}

Or you can use --data-urlencode to have CURL do the encoding:

curl -X POST --data-urlencode "activation_code=pDARI0Yxfb/BnBKw0CjsgeMtUFlei5X3uSZvNOOtjwWpfLupRk6/j8v7TnRMQHG9uFXvXTLORg7omI/MQjNNZcGBEFew5/goAG7xRa0mUbh9FEXpJOxQgT8ualYqW9WZibPH2K3SXziD4WySGQpIbCSty+ssacyq4l1OMnHi1m+jhkhqxKNtyvcuwGYg6MmleDRWTY/uY8JJfuR9A6v8yQrggqHAhbh+w5STv3g2Z/ajAmQa9Fs7TzZ/zileiDZ/" http://localhost:8080/matchITHub/engines

{"status":"OK","engine":2}

To delete an engine instance:

curl -X DELETE http://localhost:8080/matchITHub/engines/1

{"status":"OK"}

To query the state of an engine:

curl http://localhost:8080/matchITHub/engines/1/state

{"status":"OK","state":"Initialized:\nthe engine has been initialized but no settings applied"}

The --data switches can take input from a file, so:

--data-urlencode "name@filename"

will make curl load data from the given file (including any newlines), URL-encode that data and pass it on in the POST.

The name part gets an equal sign appended, resulting in name=urlencoded-file-content.

Note that the name is expected to be URL-encoded already.

So, to apply settings from a file called settings.xml we can use:

curl -X POST --data-urlencode "xml@settings.xml" http://localhost:8080/matchITHub/engines/1/settings

{"status":"OK"}

curl http://localhost:8080/matchITHub/engines/1/state

{"status":"OK","state":"Ready:\nsettings have been applied but no data has been added"}

To enable debug logging:

curl -X POST --data "severity=Debug" http://localhost:8080/matchITHub/engines/1/log

To stream a file of data we need to supply "multipart form data" so use the -F or --form option for each parameter:

curl -X POST -F "file=@example1.txt" -F "delimiter=\t" http://localhost:8080/matchITHub/engines/1/tables/1

{"status":"OK"}

curl http://localhost:8080/matchITHub/engines/1/state

{"status":"OK","state":"Aborted:\nthe engine's processing threads have been stopped, and no more data can be added."}

When state becomes "Aborted" you can fetch the errors as follows:

curl -X POST http://localhost:8080/matchITHub/engines/4/errors

{"status":"OK","errorMsgs":["Input data doesn't match the input columns' definition (record AA053502)"]}

Using the sample files installed with the service on Windows:

curl -X POST --data-urlencode "xml@exampleconfig.xml" http://localhost:8080/matchITHub/engines/6/settings

{"status":"OK"}

client>curl -X POST -F "file=@exampledata.txt" -F "delimiter=\t" http://localhost:8080/matchITHub/engines/6/tables/1

{"status":"OK"}

curl -X POST http://localhost:8080/matchITHub/engines/6/state

{"status":"OK","state":"Running:\ndata has been added, and the engine is actively processing data or waiting for more data to process"}

Now we can do lookups where the data we post must match the layout of table 2 in the settings and start with a delimiter.

I.e.

,Prefix,FirstNames,LastName,Company,Address1,City,State,Postcode

curl -X POST --data-urlencode "data=,,JOSE,ACEVEDO,,,MEXICO CITY,,15620" http://localhost:8080/matchITHub/engines/6/lookup

{"status":"OK",

"count":5,

"results":

["\t1\tJOSE ACEVEDO\tNOBELES Q, SA DE CV\tHANGAR C-11\tAEROPUERTO INTERNACIONAL\tMEXICO CITY\t\t15620\t13\t0\t0\t0\t0\t0",

"\t18\tJOAN MUELLER\tAIRWEST HELICOPTERS, INCORPORATED\t500 NORTH LINK LANE\t\tEDGEMOOR\tDELAWARE\t19802\t13\t0\t0\t0\t0\t0",

"\t48\tSE´┐¢OR J ACEVEDO\tNOBELES Q, S.A. DE C.V.\tAEROPUERTO INTERNACIONAL, HANGAR #11, ZO\t\tMEXICO CITY\tMEXICO\t15620\t13\t0\t0\t0\t0\t0",

"\t51\tSE´┐¢OR M ROBOLLEDO\tLOPATA S.A. DE C.V.\tTERMINAL DE AVIACION GENERAL, HANGAR 6,\t\tMEXICO CITY\tMEXICO\t15620\t13\t0\t0\t0\t0\t0",

"\t3\tMIGUEL ROBOLLEDO\tLOPATA S.A. DE C.V.\tTERMINAL DE AVIACION GENERAL, HANGAR 6\t\tMEXICO CITY\t\t15628\t13\t0\t0\t0\t0\t0"]}