-
Notifications
You must be signed in to change notification settings - Fork 20
HowTo | TANGO Rest API Test with curl
ML-TANGO edited this page Oct 17, 2022
·
3 revisions
cURL (curl
) is command line utility for supporting HTTP, HTTPS, FTP, SFTP, SMTP, ect.
sudo apt install curl
For unit test of Rest APIs provided and exposed by TANGO containers, following options might be used.
-
-d, --data:<data>
: send specified data in HTTPPOST
request -
-h, --header:<header>
: headers to supplied with HTTP request -
-X, --request
: the request method to use: [GET
|POST
]
cur -X GET "http://localhost:8080/hello?age=30"
- HTTP GET request had no body.
- URL should be surrounded by double quotes(
"
).
cur -d "key1=value1&key2=value2" \
-H "Content-Type: application/x-www-form-urlencoded" \
-X POST http://localhost:8000/data
You can use JSON formatted data with -d
option as follow
curl -d '{"key1":"value1", "key2":"value2"}' \
-H "Content-Type: application/json" \
-X POST http://localhost:8000/data
(base) kimkk@bravo:~/work/TANGO$ curl -X POST http://bravo.etri.re.kr:8086/api/dataset/getDataSetList
[{"DATASET_CD":"CI220002","TITLE":"ttt","DESC_TXT":"ttt","OBJECT_TYPE":"C","DATA_TYPE":"I","CRN_USR":"user","CRN_DTM":"2022-10-15T00:32:51.000Z","UPT_DTM":"2022-10-15T00:32:51.000Z","THUM_NAIL":"/static/CI220002/THUM_NORMAL-1128157-0001.jpg","CATEGORY1":"USER","CATEGORY2":null,"CATEGORY3":null,"FILE_COUNT":21,"CLASS_COUNT":3,"T_CLASS_COUNT":null,"DATA_SIZE":3644699,"DATASET_STS":"DONE","PERCENT":0,"TAGS":null,"COL_CNT":0,"RECORDS":0,"ROW_CNT":null,"ROW_TARGET":null,"PID":null,"LAST_MSG":null,"AUTO_ACC":null,"AUTO_MODEL":null,"AUTO_EPOCH":0,"UPLOAD_TYPE":null},{"DATASET_CD":"CI220001","TITLE":"test","DESC_TXT":"test","OBJECT_TYPE":"C","DATA_TYPE":"I","CRN_USR":"user","CRN_DTM":"2022-10-15T00:30:22.000Z","UPT_DTM":"2022-10-15T00:30:22.000Z","THUM_NAIL":"/static/CI220001/THUM_NORMAL-1128157-0001.jpg","CATEGORY1":"USER","CATEGORY2":null,"CATEGORY3":null,"FILE_COUNT":21,"CLASS_COUNT":3,"T_CLASS_COUNT":null,"DATA_SIZE":3644699,"DATASET_STS":"DONE","PERCENT":0,"TAGS":null,"COL_CNT":0,"RECORDS":0,"ROW_CNT":null,"ROW_TARGET":null,"PID":null,"LAST_MSG":null,"AUTO_ACC":null,"AUTO_MODEL":null,"AUTO_EPOCH":0,"UPLOAD_TYPE":null}]
(base) kimkk@bravo:~/work/TANGO$
JSON formatting with jq
$ curl -X POST http://129.254.181.46:8086/api/dataset/getDataSetList | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 568 100 568 0 0 63111 0 --:--:-- --:--:-- --:--:-- 63111
[
{
"DATASET_CD": "CI220001",
"TITLE": "test",
"DESC_TXT": "test",
"OBJECT_TYPE": "C",
"DATA_TYPE": "I",
"CRN_USR": "user",
"CRN_DTM": "2022-10-17T07:04:36.000Z",
"UPT_DTM": "2022-10-17T07:04:36.000Z",
"THUM_NAIL": "/static/CI220001/THUM_NORMAL-1128157-0001.jpg",
"CATEGORY1": "USER",
"CATEGORY2": null,
"CATEGORY3": null,
"FILE_COUNT": 21,
"CLASS_COUNT": 3,
"T_CLASS_COUNT": null,
"DATA_SIZE": 3644699,
"DATASET_STS": "DONE",
"PERCENT": 0,
"TAGS": null,
"COL_CNT": 0,
"RECORDS": 0,
"ROW_CNT": null,
"ROW_TARGET": null,
"PID": null,
"LAST_MSG": null,
"AUTO_ACC": null,
"AUTO_MODEL": null,
"AUTO_EPOCH": 0,
"UPLOAD_TYPE": null
}
]
- You can use online json viewer for readability of the above output
$ curl -X GET 'http://129.254.181.46:8095/start?user_id="test"&project_id="test"'
starting
$
$ $ curl -I -X GET 'http://129.254.181.46:8095/start?user_id=test&project_id=test'
HTTP/1.1 200 OK
X-Powered-By: Express
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: X-Requested-With
Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE
Content-Type: text/html; charset=utf-8
Content-Length: 8
ETag: W/"8-lJOvBXsCOH2X3hzWtHQnC2qA1lg"
Date: Mon, 17 Oct 2022 07:15:54 GMT
Connection: keep-alive
Keep-Alive: timeout=5
$
For further information on curl, refer to
- curl POST examples - gists · GitHub
- Everything curl - online book on curl
👉Note
- This page might contain some wide rendered images. If you want to see the whole contents with wider page, please use Wide GitHub extension of Chrome.
- If you are experiencing the error on rendered images due to the low-bandwith Internet delay, please use F5 function key for refreshing current page.