cppp-io icon indicating copy to clipboard operation
cppp-io copied to clipboard

Param ordering specificaton using JSON is not correct in cylon-api-http(CPPP-IO base HTTP cylon API)

Open kendemu opened this issue 8 years ago • 0 comments

Hello, I'm making a drone app controlling from HTTP REST using the cylon-api-http module which describes that the API specification is documented in the CPPP-IO. However, when I wrote this Ajax POST code in JavaScript seeing the CPPP-IO specification, it doesn't work.

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:3001/api/robots/Scratch4D/devices/drone/commands/front", false);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send({"a": speed});

However, when I did this HTTP Request from cURL, it works.

curl localhost:3001/api/robots/Scratch4D/devices/drone/commands/front -d params=1.0

When I looked the HTTP Header of this request, I was very surprised.

0000: POST /api/robots/Scratch4D/devices/drone/commands/front HTTP/1.1
0042: Host: localhost:3001
0058: User-Agent: curl/7.47.0
0071: Accept: */*
007e: Content-Length: 10
0092: Content-Type: application/x-www-form-urlencoded
00c3: 
=> Send data, 10 bytes (0xa)
0000: params=1.0
== Info: upload completely sent off: 10 out of 10 bytes
<= Recv header, 17 bytes (0x11)

This request doesn't use any JSON. The content type is not application/json. And the body is not JSON object.

From this information, I implemented my app with this code. (working code)

var xhr = new XMLHttpRequest();
xhr.open("POST", "http://localhost:3001/api/robots/Scratch4D/devices/drone/commands/front", false);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xhr.send("params="+speed.toString());

Is your specification document correct? The JSON format doesn't works.

kendemu avatar Feb 06 '17 14:02 kendemu